0

I am following this example - http://jqueryui.com/selectable/#serialize and would like to be able to set the value of a hidden input field based on the user selection. So rather than the value being displayed as per the example, that value instead would be consecutively added to the hidden input field value. How can I achieve this?

<input type="hidden" />

6
  • 3
    what is the question? Commented Jun 10, 2013 at 3:22
  • You have to go to the Link I have provided. It is an example of JQuery. The value returned by selecting it in the html, but I want to put this value in < input type = "hidden"/>. Commented Jun 10, 2013 at 3:25
  • selected value will be in the form of HTML, so do you want the selected values to be translated into hidden fields? Commented Jun 10, 2013 at 3:26
  • So, suppose I selected values 1, 2, and 3. Should it look like <input type="hidden" name="values" value="1,2,3">? Commented Jun 10, 2013 at 3:26
  • @DaveChen Yes, you are. Commented Jun 10, 2013 at 3:31

1 Answer 1

1

If you want the selected value to be placed in your hidden field, add a class or id to your hidden input, and then change the following lines from the source example page:

your hidden input

<input type="hidden" id="hiddenInput" />

from the example, change

var result = $( "#select-result" ).empty();

to your hidden input

var result = $('#hiddenInput').empty();

then change

result.append( " #" + ( index + 1 ) );

to

result.val('#' + (index + 1));

to add the values rather than replace them, change the line to

result.val(result.val() + "#" + ( index + 1 ) );

here is a working example - http://jsfiddle.net/DBuVf/1

Sign up to request clarification or add additional context in comments.

2 Comments

But I suspect that If you select multiple time slots, such as select .append channels 1, 3, 5, the value will be the value of the array is 3. But enough change to get the last value val one. If we want to have all three, and is in the form that I want to do it or not.
I updated the answer for you so that it adds each value to the hidden input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.