Get the value of an input field with the val() method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:val

Description

Get the value of an input field with the val() method

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("Value: " + $("#test").val());
    });/*from  www. j a  v a2 s. c  o m*/
});
</script>
</head>
<body>

<p>Name: <input type="text" id="test" value="Mickey Mouse"></p>

<button>Show Value</button>

</body>
</html>

Related Tutorials