php - JavaScript error in function which calcs sum of two values -
This is my JS code to match two digits
script type = "text / javascript" & gt; Function match () {var a = parseInt (document.getElementById ("a")); Var b = parseInt (document.getElementById ("two")); Var c = parseInt (document.getElementById ("sum")); var d; D = a + b; If (D! = C) {Warning ("something is wrong !!"); } And {warnings ("success"); }} & lt; / Script & gt; To generate the HTML code two digits and check this process.
& lt; form action = "#" method = "post" onsubmit = "return match ();" & gt; & Lt; input type = "text" name = "one" id = "one" value = "& lt ;? php echo rand (1,9);?> & gt; Read-only = "Read-only" /> + & lt; Input type = "text" name = "two" id = "two" value = "& lt ;? php echo rand (1,9);?> & Gt;" Read-only = "Read-only" /> = & Lt; Input type = "text" name = "yoga" id = "sum" /> & Lt; Input type = "submit" value = "submit" /> & Lt; / Form & gt;
Maybe you want them to be assessed and not just elements.
var a = parseInt (document.getElementById ("a"). Value, 10); var b = parseInt (document.getElementById ("two"). value, 10); var c = parseInt (document.getElementById ("sum") value, 10); Additionally, when you are using parseInt () then provide radix otherwise it may sometimes be crazy is.
Comments
Post a Comment