How to take value from radio selection and pass that value into a hidden inputs value attribute?

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2010-06-14T18:03:20Z Indexed on 2010/06/14 18:12 UTC
Read the original article Hit count: 150

Filed under:
|
|

Hello guys,

I need to know if this can be done and if so can someone push me in the right direction.

Okay I have a series of radio buttons:

<input type="radio" name="level_id" id="radio1" value="XXXX" class="radio1" />
<label for="radio1">choice 1</label>

<input type="radio" name="level_id" id="radio2" value="XXXX" class="radio2" />
<label for="radio2">choice 2</label>

<input type="radio" name="level_id" id="radio3" value="XXXX" class="radio3" />
<label for="radio3">choice 3</label>

<label for="radio4">second choice1</label>
<input type="radio" name="level_id" id="radio4" value="1" class="radio4" />

<label for="radio5">second choice2</label>
<input type="radio" name="level_id" id="radio5" value="2" class="radio5" />

<label for="radio6">second choice3</label>
<input type="radio" name="level_id" id="radio6" value="3" class="radio6" />

Now what I am looking to do is if someone selects CHOICE 1 and then selects SECOND CHOICE1 I would like to pass the value of SECOND CHOICE1 into the value of a hidden input.

<input type="hidden" name="sub_source" id="sub_source" value="" />

So that when the form is ready to submit the value that gets passed would be:

<input type="hidden" name="sub_source" id="sub_source" value="1" />

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about forms