jquery - How would I store the number in an html form input as a javascript variable when a button is clicked? -


basically want when user types number in html form input field presses submit button, number stored in javascript variable.

<input type="number" min="1" name="number">  var number = ? 

how javascript or jquery?

thank you.

here javascript solution, use until jquery comes built browser ( might aswell be, seeing it's the savior )

<form id="form">   <input id="number" type="number" min="1" name="number">   <button>submit</button> </form>  var form = document.getelementbyid('form');     number = document.getelementbyid('number'); form.onsubmit = function() {    var variable = number.value;    alert( variable ); }; 

just assign submit handler, , value of input.

my advice though, please not download jquery can store variable.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -