If you have a group of radio buttons and want to get the selected button, the code is slightly different because they all have the same name. Using the above code examples will show the value for the first radio button on the form with that name. To find out the value of the checked one, do this instead:
You can set the form values with jQuery using the same val() function but passing it a new value instead. Using the same example forms above, you'd do this for the text input and select box:
Using the above for a radio button will change the actual value of the radio button rather than changing the one that is selected. To change the radio button that is selected you'd do this:
Getting a form value with jQuery<br />To get a form value with jQuery use the val() function. Let's say we have a form like this, using an id for each form element:view sourceprint?1<inputname="foo"id="foo"type="text"> 2 3<selectname="foo"id="bar"> 4 <