cleary1981 Posted November 24, 2008 Share Posted November 24, 2008 Hi, I am having a problem when comparing two numbers. Basically what I am doing is comparing the value of two variables. If var A is less than var B show an error. Trouble is when var A is 1000 and var b is 200 I get the error message. I think it is only comparing the first 3 digits. Can anyone help. Heres the function. function generate() { var sub = document.getElementById("selectsub").value; var mod = document.getElementById("selectmod").value; var actH = document.getElementById("selectheight").value; var actW = document.getElementById("selectwidth").value; var actD = document.getElementById("selectdepth").value; var minH = document.getElementById("minh").innerHTML; var minW = document.getElementById("minw").innerHTML; var minD = document.getElementById("mind").innerHTML; var label = document.getElementById("modlabel").value; if (document.form1.modlabel.value.length == 0) { alert("You must label the module!"); } else { //alert(actH + minH); if ((actH < minH) || (actW < minW) || (actD < minD)) { alert("Dimensions are below the minimum for this module!"); } else { var url = "create_object.php?sub=" + escape(sub) + "&mod=" + escape(mod) + "&actH=" + escape(actH) + "&actW=" + escape(actW) + "&actD=" + escape(actD) + "&label=" + escape(label) + "&panel=" + escape(panel); url = url + "&dummy=" + new Date().getTime(); request.open("GET", url, true); request.onreadystatechange = showObject; request.send(null); } } } Quote Link to comment https://forums.phpfreaks.com/topic/134028-solved-comparison-problem/ Share on other sites More sharing options...
KevinM1 Posted November 24, 2008 Share Posted November 24, 2008 Hi, I am having a problem when comparing two numbers. Basically what I am doing is comparing the value of two variables. If var A is less than var B show an error. Trouble is when var A is 1000 and var b is 200 I get the error message. I think it is only comparing the first 3 digits. Can anyone help. Heres the function. function generate() { var sub = document.getElementById("selectsub").value; var mod = document.getElementById("selectmod").value; var actH = document.getElementById("selectheight").value; var actW = document.getElementById("selectwidth").value; var actD = document.getElementById("selectdepth").value; var minH = document.getElementById("minh").innerHTML; var minW = document.getElementById("minw").innerHTML; var minD = document.getElementById("mind").innerHTML; var label = document.getElementById("modlabel").value; if (document.form1.modlabel.value.length == 0) { alert("You must label the module!"); } else { //alert(actH + minH); if ((actH < minH) || (actW < minW) || (actD < minD)) { alert("Dimensions are below the minimum for this module!"); } else { var url = "create_object.php?sub=" + escape(sub) + "&mod=" + escape(mod) + "&actH=" + escape(actH) + "&actW=" + escape(actW) + "&actD=" + escape(actD) + "&label=" + escape(label) + "&panel=" + escape(panel); url = url + "&dummy=" + new Date().getTime(); request.open("GET", url, true); request.onreadystatechange = showObject; request.send(null); } } } Hmm...why are you using innerHTML to retrieve certain values? Quote Link to comment https://forums.phpfreaks.com/topic/134028-solved-comparison-problem/#findComment-697657 Share on other sites More sharing options...
Adam Posted November 24, 2008 Share Posted November 24, 2008 It will be treating them as strings and comparing the length. need to convert them to integers.. Look into the parseInt() and parseFloat() functions .. Adam Quote Link to comment https://forums.phpfreaks.com/topic/134028-solved-comparison-problem/#findComment-697662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.