File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes onclick event(alert) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onclick event(alert)" Watch "onclick event(alert)" New topic

onclick event(alert)

padmshree Patil
Ranch Hand

Joined: Dec 18, 2000
Posts: 54
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 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 " )
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???
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
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.
I agree. Here's the link:
subject: onclick event(alert)
It's not a secret anymore!