I am trying to pop out input box value but it is showing a blank value. why? Here is the jsfiddle.
$(document).ready(function() {
var name = $("#name").val();
$('#showName').click(function() {
alert(name);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="name" placeholder="First Name">
<button type="button" id="showName">Show name</button>
See Question&Answers more detail:os