Saturday, 15 September 2012

Error messages not displaying for form validation Javascript -


Actually not sure what I did wrong. But two of my errors are not displayed, NPIS and NAM, however, display my name and nSmokes, I am thinking that if I am doing this with it, then I am using it.

I thank you in advance.

function doValidate () {// warning ("work"); Document.myForm.nPrice.value = parseFloat (document.myForm.nPrice.value); Document.myForm.nAmount.value = parseInt (document.myForm.nAmount.value); Document.myForm.nSmokes.value = parseInt (document.myForm.nSmokes.value); //alert(document.myForm.nPrice.value); //alert(document.myForm.nAmount.value); //alert(document.myForm.nSmokes.value); ErrorCount = 0; ErrorMsg = "" if (document.myForm.name.value == "") {errorMsg = errorMsg + "You need to enter a value!"; Document.getElementById ('Errors'). InnerHTML = errorMsg; ERRORCOUNT ++; } If (document.myForm.nPrice.value & lt; 0 & amp; amp; amp; amp; amp; amp; amp; amp; amp; document documentation.myForm.nPrice.value & gt; 20.00) {errorMsg = errorMsg + "You enter a value between 0 and 20 is required!"; Document.getElementById ('Errors'). InnerHTML = errorMsg; ERRORCOUNT ++; } If (document.myForm.nAmount.value & lt; 0 & amp; amp; amp; amp; amp; amp; documents.MyForm.nAmount.value & gt; 40) {errorMsg = errorMsg + "You between 0 and 40 Need to enter a value! "; Document.getElementById ('Errors'). InnerHTML = errorMsg; ERRORCOUNT ++; } If (document.myForm.nSmokes.value & lt; 0) {errorMsg = errorMsg + "

either you are doing a great job or you have smoked what you have smoked today! "; Document.getElementById ('Errors'). InnerHTML = errorMsg; ERRORCOUNT ++; } If (error group> 0) {return false; } And {return true; }}

  & lt; Form name = "myForm" method = "post" id = "myForm" onsubmit = "return doValidate ();" & gt; & Lt; Width of table = "600" range = "1" cellpaction = "4" cellpadding = "4" & gt; & Lt; TR & gt; & Lt; Td colspan = "2" align = "center" & gt; & Lt; Img src = "quitSmoking.jpg" width = "278" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "2" align = "center" & gt; Quit smoking calculator by your name & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Your name & lt; / Td> & Lt; Td> & Lt; Input type = "text" name = "name" id = "name" /> and & nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> The date you left & lt; / Td> & Lt; Td> & Lt; Input name = "start date" type = "text" & gt; & Lt; Input type = "button" value = "select" onclick = "displayDatePicker ('startdate');" & Gt; & Amp; Nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Price of a pack & lt; / Td> & Lt; Td> & Lt; Input type = "text" name = "nPrice" id = "nPrice" value = "8.00" /> & amp; Nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> How many packs & lt; / Td> & Lt; Td> & Lt; Input type = "text" name = "nmount" id = "nmount" value = "20" /> & Amp; Nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> The number of cigarette you smoke a day & lt; / Td> & Lt; Td> & Lt; Input type = "text" name = "nSmokes" id = "nsmokes" value = "25" /> & Amp; Nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "2" align = "center" & gt; Input type = "submit" name = "submit btn" id = "submit btn" value = "calculate saving" gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "2" align = "center" & gt; & Lt; Div id = "errors" & gt; & Lt; / Div & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td id = "rowResult" colspan = "2" align = "center" & gt; & Lt; Input type = "hidden" name = "nResult" id = "nResult" value = "" /> & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / Form & gt;    

  document.myForm.nPrice.value & lt; 0 and amp; Amp; Document.myForm.nPrice.value & gt; 20.00   

How can the value be less than 0 and greater than 20? You or you are searching there.

  document.myForm.nPrice.value & lt; 0 || Document.myForm.nPrice.value & gt; 20.00   

or between 0 to 20

  document.myForm.nPrice.value & gt; 0 and amp; Amp; Document.myForm.nPrice.value & lt; 20.00   

The same kind of mistake that you made for another if expression is also.

No comments:

Post a Comment