How to use HTML Val Method in JQuery
This article describe about HTML Val Method in JQuery.
HTML val() method in jQuery
Syntax
Example
The following example show the use of val() method.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("button").click(function ()
{
alert($("input:text").val());
});
});
</script>
</head>
<body>
Firstname: <input type="text" name="fname" value="Hello" /><br />
Lastname: <input type="text" name="lname" value="World" /><br />
<button>Return the value of the first text field</button>
</body>
</html>
|
Output1
Output2
Using a Function
val() method using function to set the value of the value attribute for all selected elements.
Syntax
$(selector).val(function(index,oldvalue))
|
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here