Monday, 15 April 2013

javascript - how to make bind submit working always? it's working from time to time -


If maximum is greater, then I'm trying to compare values ​​(minimum-max) with two inputs. Which works

The problem occurs when I correct the maximum value and submit it again, this is showing the same warning ...

This is my HTML is:

> pre & lt; & Lt; Input type = "text" placeholder = "min" id = "input1" class = "numberInput" /> & Lt; Input type = "text" placeholder = "max" id = "input2" class = "numberInput" /> & Lt; Input type = "submit" / & gt; & Lt; Span class = "msg" & gt; & Lt; / Span & gt; & Lt; / Form & gt;

And this is my (relevant?) JS:

  var $ input1 = $ ("# input1"); Var $ input2 = $ ("# input2"); $ (Document) .ready (function () {$ ('form'). Bind ("submit", function (e) {if ($ input1.val ()> gt; $ input2.val ()) { Warning ('minimum value exceeds maximum value); $ input1.focus (); e.preventDefault ();} and {warnings (' normally submitted '); evt.preventDefault ();}})}) < / Code> 

you

thanks

Can get full sample

.val () returns a string, so

  $ input1.val ()> $ Input2.val () === When input1 = "7" and input2 = "456456"  

To avoid that compartment you must use the parseInt () function

Parseint ($ input1.val ()) & gt; ParseInt ($ input2.val ()) === Incorrect when input1 = "7" and input2 = "456456"


No comments:

Post a Comment