Question: I want to retrieve the value of an input using jQuery.

Here's the HTML:

```
<input type="text" name="a" id="a" />
<input type="button" name="b" id="b" value="Click here"/>

```

Here's the jQuery:

```
$(document).ready(function() {

    var normal=$('#a').val();
    $('#b').on("click", function() {
            alert(normal);
  });

});

```

Due to some reason the `alert(normal);` does not work whereas `alert($('#a').val());` does. Why? Isn't `normal` and `$('#a').val();` holding the same value?

In case you want a jsfiddle: <http://jsfiddle.net/L2uX4/20/>

Thanks

Answer: 
if you declare `var normal` outside the click function handler then the initial value will be empty as there is no value in the text box once the DOM is ready . But if you declare it within the `click` event handler then the value will be assigned once you type something in the textbox and click the button.
The below code works for me 

```js
$(document).ready(function() {

    $('#b').on("click", function() {
          var normal= $('#a').val();
         alert(normal);
        // same as alert($('#a').val());
  });

});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="a" id="a" />
<input type="button" name="b" id="b" value="Click here"/>
```
Try this code 

```
$(document).ready(function() {

        $('#b').on("click", function() {
        var normal=$('#a').val();
        alert(normal);
      });

    });

```