Jquery Setting Value of Input Field

The val() method returns or sets the value attribute of the selected elements.

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.

HTML Code

<input id="userName" name="userName" type="text" value=""/>

jQuery Code

$("#userName").val("Script_gurus")

Empty Value

$("#userName").val("")

Leave a Reply

Your email address will not be published. Required fields are marked *