Copyright © tutorialspoint.com

jQuery - val( val ) Method

previous next


Advertisements

Description:

The val( val ) method sets the input value of every matched element.

If this method is called on radio buttons, checkboxes, or select options then it would checks, or selects them at the passed value.

Syntax:

Here is the simple syntax to use this method:

selector.val( val ) 

Parameters:

Here is the description of all the parameters used by this method:

Example:

Following example would set the value attribute of the second input with the value content of the first input:

<html>
<head>
<title>The Selecter Example</title>
<script type="text/javascript" src="/jquery/jquery-1.3.2.min.js">
</script>
   
<script type="text/javascript" language="javascript">

   $(document).ready(function() {
      var content = $("input").val();
      $("input").val( content );
   });

</script>
</head>
<body>

<input type="text" value="First Input Box"/><br/>
<input type="text" value="Second Input Box"/>

</body>
</html>

This would generate following result.

<html>
<head>
<title>The Selecter Example</title>
<script type="text/javascript" src="/jquery/jquery-1.3.2.min.js">
</script>
   
<script type="text/javascript" language="javascript">

   $(document).ready(function() {
      var content = $("input").val();
      $("input").val( content );
   });

</script>

</head>
<body>

<input type="text" value="First Input Box"/><br/>
<input type="text" value="First Input Box"/>

</body>
</html>

To understand it in better way you can Try it yourself.


previous next

Copyright © tutorialspoint.com