This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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