Reputation: 41
I am having a problem with my html document. I am trying to find the value of the iput box below but it wont work. It has that the value is blank. I am running to document as a file in my computer, not on the web, if that makes a difference. This is my html code:
<p class='textcenter'>What would you like to scan</p><input id='scanbox1' type='text' name='scanboxtype'>
And this is my jquery:
var a;
a = $('input[name=scanboxtype]').val();
alert('a is '+a)
What ever i type in, the alert pops up as 'a is'. Thanks for the help.
Upvotes: 1
Views: 175
Reputation: 18064
You haven't triggered the alert either on submit or on change or any other events.
So you don't see the alert message with the value
Always result will be "a is"
Using .change()
$('input[name=scanboxtype]').change(function(){
alert('a is '+ this.value); // or $(this).val()
});
Using .keyup()
$('input[name=scanboxtype1]').keyup(function(){
alert('a is '+ this.value); // or $(this).val()
});
Refer LIVE DEMO
Upvotes: 1
Reputation: 4968
Maybe your code is running when the key is pressed for example, but the value is not yet in the input element? For example on 'keydown' or something?
Upvotes: 0