jQuery set and get form element values
jQuery is a Javascript framework which simplify Javascript coding complexity and also fixed cross browser issues. You can get and set html form element values by using jQuery.
Getting a form value with jQuery
jQuery uses val() function to get a form values. Below is the example form with id city.
- <form>
- <input name=“city” id=“city” type=“text”>
- </form>
Now we will get the value from id “city” and display an alert:
- window.alert( $(‘#city’).val() );
If you’re using the name only and not specifying an id, the jQuery to get the form values would be this:
- window.alert( $(‘[name=city]‘).val() );
Setting a form value with jQuery
You can easilly set the form values with jQuery using the same val() function but passing it a new value. Using the same example forms above, you can do this for the text input.
- $(‘#city’).val(‘city value’);
OR
- $(‘[name=city]‘).val(‘city value’);
Follow @phpzag

hi!,I like your writing so a lot! share we communicate extra about your post on AOL? I require an expert on this area to solve my problem. May be that’s you! Having a look ahead to see you.
Ahaa, its pleasant conversation regarding this paragraph here at this web site, I have
read all that, so at this time me also commenting here.