java - display error message in jsp with javascript -
I have a jsp file that has a form and I have to validate the form. The Jsp page will be opened as a pop-up page and therefore I do not want to pop up the verification message again. Here's my code.
& lt; script type = "text / javascript" & gt; Function validateForm () {var x = document.forms ["myForm"] ["name1"] value; If (x. Tram (). Length & lt; = 4) {return false; }} & lt; / Script & gt; & lt; form name = "myForm" method = "POST" verb = "write.jsp" onsubmit = "return validateForm ();" & gt; Name: & lt; Input type = "text" name = "name1" value = "& lt;% = name%>" Size = "20" /> & Lt; Br> Price: & lt; Input type = "text" name = "value" value = "& lt;% = value%>" Size = "20" /> gt; & Lt; Br> Deadline: & lt; Input type = "text" name = "free" value = "& lt;% = dueday%>" Size = "20" /> gt; & Lt; Br> Location: & lt; Input type = "text" name = "location" value = "& lt;% = address%>" Size = "20" /> gt; & Lt; Br> Photo URL: & lt; Input type = "text" name = "url" value = "& lt;% = imagePath%>" Size = "20" /> gt; & Lt; Br> Details: & lt; Input type = "text" name = "desc" value = "& lt;% = desc%>" Size = "20" /> gt; & Lt; Br> & Lt; Input type = "submit" name = "submit" onclick = "window.close ()" /> & Lt;% If (validateForm = false) {%> & Lt; A & gt; Error message & lt; / A & gt; & Lt;%}% & gt; & Lt; / Form & gt; I am valid for input "name1" and input length is less than 4. / I want to display an error message below the submit button code is not working, can someone help me fix this?
document.getElementsByName 'name1') [0] .Value; In place of
document.forms ["myForm"] ["name1"]. Values;
Use a span below the submit button - html
& lt; Span id = "error" & gt; & Lt; / Span & gt; script
validate the function (form) {var x = document.getElementsByName ('name1') [0] .value; If (x.trim (). Length & lt; = 4) {document.getElementById ("Error"). InnerHTML = "At least 4 characters in name"; return false; }}
Comments
Post a Comment