javascript - .val assign to variable on submit of form -


How can I perform this variable counting function when a user hits the submit button?

  Var size = $ ("# size"). Val (); & Lt; Input id = "size" /> & Lt; Button type = "submit" & gt; Calculation! & Lt; / Button & gt;  

They should be assumed to be input and store it in variable = size

Is it possible that the user reloaded without reloading this page Output it back without JQuery? P>

Attach an event handler to submit form event

Original example

HTML

prevent event handler from sending form to preventDefault () Should call for.

/ P>
  & lt; Forms & gt; & Lt; Input id = "size" /> & Lt; Button type = "submit" & gt; Calculation! & Lt; / Button & gt; & Lt; / Form & gt; & Lt; Div id = "output" & gt; & Lt; / Div & gt;  

JavaScript

  var size; $ ("Form") Submit (function (e) {e.preventDefault (); // size = $ ("# size") prevents submitting. Val (); $ ("# output"). Text (size);}) ;   

JS Friedl:


Use of Bedle Code

Javascript

  $ ("#cushionCalculator"). Submit (function (e) {e.preventDefault (); var size = $ ("# size"). Val (); $ ("# output"). });  

Fiddle will use your code:


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -