I want To get The Value that User Entered in the input box using jquery | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I want To get The Value that User Entered in the input box using jquery

Hi!

18th May 2018, 3:01 PM
Naqib Ali
Naqib Ali - avatar
4 Answers
+ 2
$("#myInputBox").val()
18th May 2018, 3:22 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
Post your code? If you're calling that function before you enter anything in the input box, then it'll return empty because it's empty. So you'll want it to check the val() of the input box when the user clicks 'submit' or 'ok' or whatever is being used. If you further explain your situation, I can tell you exactly how to do it. If you can post your code, that'll work even better.
18th May 2018, 3:35 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
https://code.sololearn.com/WP3nMrCOOQjg/#html <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <input id="myInputBox" type="text"/> <button id="myButton" > Ok </button> <div id="myDiv"></div> </body> </html> <script> $(function() { $('#myButton').click(function(){ $('#myDiv').text("Input Value: " + $('#myInputBox').val()); }); }); </script>
18th May 2018, 3:58 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
returns emty
18th May 2018, 3:31 PM
Naqib Ali
Naqib Ali - avatar