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: 
You're assigning `normal` upon `document.ready()` and not reassigning when you click, so normal will be whatever value you give to the input field when the page loads.
Yes, you are right,

> 
> provided the text box with `id= a` had some text on load.
> 
> 
> 

by that I mean something along the lines of 

```
<input type="text" name="a" id="a" value= "foo"/>

```

Fiddle: <http://jsfiddle.net/Jayas/vhjm8v31/2/>

Now if you hit `Clickhere` button it will display `foo`.

**In your case**

1. When you assign the value of `a` to `normal` the text box is empty.
2. You dont have any handlers or events hooked up to reset/set the variable `normal`on something being typed or after something has got typed in. by that I mean something along the lines of having the value stored on `input change` along the lines of

```
$(document).ready(function(){
 $('#a').bind('input propertychange', function() {
      normal = $('#a').val();
     }
 })

```

**Fiddle** <http://jsfiddle.net/Jayas/vhjm8v31/4/>

> 
> tl:dr - rebinding of the text to the declared variable does not "automagically" happen
> 
> 
> 

So now when you click on the button after reassigning `normal` you will see the typed value.

or alternatively you can capture the value of normal on click event as you already have it , along the lines of

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

```