Return the value of the first input field - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:val

Description

Return the value of the first input field

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        console.log($("input:text").val());
    });/*  w ww  .  j  av a  2 s  . com*/
});
</script>
</head>
<body>

Firstname: <input type="text" name="fname" value="Peter"><br>
Lastname: <input type="text" name="lname" value="Griffin"><br><br>

<button>test</button>

</body>
</html>

Related Tutorials