We have created a questionnaire application.
In that we are providing a user to enter one question and multiple answers and submit to store this questionnaire to DB.
For adding multiple answers for a single question, we need to dynamically add a row by clicking on add button and delete button for deleting the row on UI.
Now my question is:
How can I implement the feature of dynamically give a row to enter multiple answers?
Once multiple answers are added, how I will get multiple answers in the form field to add that in DB?
You can use an array to get all the different values.
E.g.
<input type="text" name="answer[]">
<input type="text" name="answer[]">
<input type="text" name="answer[]">
Regarding adding the extra rows:
what have you tried so far?
What do you have troubles with?
Do you have a specific question?
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm a relatively new Rails developer with a heavy Java/C# background and I'm trying to pass multiple time ranges from my view to my controller. For instance, the user could select the time range 9:00am to 11:00am as well as 2:00pm to 4:00pm. The first thing to came to mind was a list of times or a list of key value pairs so that I know when a time range starts and ends. I'm having trouble figuring out how to pass this information to my Rails controller though.
Is there an ideal Rails way of passing a list to a controller?
From Rails Guide http://guides.rubyonrails.org/action_controller_overview.html
request
GET /mytime?t[]=1&t[]=2&t[]=3
in view
<form method="GET" action="mytime">
<select multiple name="t[]">
<option value="1">1:00pm</option>
<option value="2">2:00pm</option>
<option value="3">3:00pm</option>
</select>
</form>
or
<form method="GET" action="mytime">
<input type="text" name="t[]">
<input type="hidden" name="t[]" value="11">
</form>
#in mytime_controller.rb
def index
params[:t] # return Array of values
end
You pass information from a view to a controller via http query string ('get') or form data ('post').
I would consider multi-select dropdown for this case.
Instead of dropdown i suggest you should create a cool for using some jquery plugin that will improve your application's user experience and yes create a rails form and submit it then you can have information in your controller.
Now is you are saving these selected time, that i think you should do then create a model if you haven't already and use form_for else your can use form_tag for your rails application.
Visit Here and find some time picker that suits you need.
Here is the answer from another question: jQuery find $.find('selector') versus $('selector') difference
The reason this does not work is because find() lets you filter on a set of elements based on a selection you've already made.For example if you wanted to select all of the inputs within a particular form, you could write:
$('#aParticularForm').find('input')
It cannot be called on its own.
How can I expand this statement to find specific inputs on a page? (Specifically listviews)
Working example: http://jsfiddle.net/Gajotres/93VFG/
Wanted element must have a unique identification, like id or class.
HTML :
<form id="aParticularForm">
<input type="text" value="One" id="input1"/>
<input type="text" value="Two" id="input2"/>
</form>
Javascript :
var input = $('#aParticularForm').find('#input1');
alert(input.val());
You can even go further, because you are working with a jQuery Mobile you can have several pages loaded into the DOM and they can all have identical input fields, so to find elements only in a current active page you would use:
$.mobile.activePage.find('#input1');
I have a very simple object that needed an approved checkbox and a Declined checkbox
How can I check to make sure that both aren't checked?
A user should only check one, not both.
As #Christopher Marshall pointed out - this functionality is accomplished by the radio button type. Just change type="checkbox" to type="radio" and make sure the name is the same
I would love to use the:
Html.EditorFor(model => #Data.Test.Correct)
To create a checkbox.
However the source of my data is different from the data that needs to be updated. I know this may sound confusing but I get my data from a LINQ select query and then need to update in a different place.
The only way around this seems for me to hand code the HTML for the checkbox. But can someone give me an example of how I do this. For example, how can I code in the setting of checked=true?
You may write HTML codes like below to create a selected or unselected checkbox
<input type="checkbox" name="option1" value="1" checked="checked" />
<input type="checkbox" name="option2" value="2" />
But you will need to write additional code manually to determine which checkbox should be selected, if your checkbox is dynamic generated or being filled in with stored data.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How does StackOverflow generate its SEO-friendly URLs?
I made a simple form that contains the NAME and some other fields.
When user submits form, the following route will be called:
~/Profile/NAME
If user entered John Smith as NAME, my URL will be:
~/Profile/John%Smith
And I want it to be:
~/Profile/John-Smith
The application will display user details and again the same form at the top of the page.
NAME value will be passed to the form via ViewData.
I want to populate text box with John Smith, not John-Smith.
How can I do that? I ran out of ideas.
Thanks in advance!
EDIT:
I have found solution here: http://goneale.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/.
It needs a little modification, but basically this is it.
HttpUtility, look into UrlDecode / UrlEncode
Edit
Use jQuery. Pseudo:
<input type="text" value="name" />
<input type="submit" id="submit" />
The jQuery
$('submit').click(function() {
$('name').val($('name').val().replace(' ', '-'));
});
It can look something like that, and when you want to display it, you just replace - with space, but remember, there are names that contain - and should not be replaced.
If it helps any, I used this from Jeff Atwood as well as the link you garnered above to make it happen.