This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
Consider Paul's rocket mass heater.
subject: onclick event(alert)
Similar Threads
HTTP status 500
Prevent the page refreshing
Javascript not executing in WSAD test server
onclick event(alert)
Java Script problem