Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onclick event(alert)

 
padmshree Patil
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have one longin page(Login.html)
Here I am validating for entry in LID and PW field.
After entering login id and PW it is going to Login.java Servlet
But problem is
When user doesn't enter LID or PW ,I am showing alert and set ing focus to
that filed.
if( document.forms[0].LId.value =="" &&
document.for[0].PW.value =="" )
{
alert( "you must enter valid Id and Password " )
document.forms[0].LId.focus()
}
this code is on validate function.
and clling this as
<INPUT TYPE="SUBMIT" VALUE="Login" onclick = 'validate( this )'>
it woking fine but when I add
<FORM ACTION="http://localhost:8100/servlet/Login" METHOD="POST">
After alert it directly goes to Servlet
What I have do???
Thanks,
padmasshree
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of having an onClick that runs the function, have an onSubmit = validate(this) in your FORM tag. Then in your function, make sure you return false; if you do not want to submit the form, and return true; if they entered the values correctly and you do want to submit the form.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic