javascript - Validating form in jsp page -
I have a form with the input named '1 name', I want to validate this input, make sure Take that there is at least four characters here in my code.
& lt; script type = "text / javascript" & gt; Function validateForm () {var x = document.forms ["myForm"] ["name1"] value; If (x == ft. X == "") {warning ("name should be filled"); return false; }} & lt; Form name = "myForm" method = "POST" action = "write.jsp" onsubmit = "return validateForm ()" & gt; Name: & lt; Input type = "text" name = "name1" value = "& lt;% = name%>" Size = "20" /> & Lt; Br> & Lt; Input type = "submit" name = "submit" onclick = "window.close ()" /> & Lt; / Form & gt; This is not working, I think it is a pop-up page and the warning from Javascript has not been popped up again. Can anyone help me in solving this problem ??
try it,
validate the function () {var x = Document.forms ["myForm"] ["name1"]. Values; If (x.trim (. Length = lt; = 4) // test length of your name field {warning ("name should be filled"); return false; }}
Comments
Post a Comment