I am trying to capture the value from my text input, and now I am alerting it by clicking the button. For whatever reasons is the alert always remain empty? I have tried many different ways to go about this, but none of them have done any work. Please help me: \
As you can see.
My HTML:
& lt; Input type = "article" id = "item_text" /> & Lt; Button ID = "Button 1" & gt; Clicks & lt; / Button & gt; My jQuery:
$ (document) .ready (function () {value = $ ("# item_text"). Attr ('value' ); $ ("# Button1"). Click (function () {warning (value);});});
You have a price set on page load, then print on the click so if you have
& lt; Input type = "text" id = "item_text" /> has been changed ... to ...
& lt; Input type = "text" id = "item_text" value = "waffles" /> ... then the output will always be waffles. What do you want to do, check the value on the click, and then print it.
The easiest way to fix this, is to check the value inside the click function like this:
$ (document) .ready (function () {$ ("# Button1"). (Function () {value = $ ("# item_text"). Attr ('value'); alert (value);});}); As others have said, it is better to use .attr ('value') instead of .value () . Either way though it will work
Comments
Post a Comment