File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets 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 » Java » Servlets
Bookmark "onclick event(alert)" Watch "onclick event(alert)" New topic
Author

onclick event(alert)

padmshree Patil
Ranch Hand

Joined: Dec 18, 2000
Posts: 54
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???
padmasshree
bredan
Greenhorn

Joined: Dec 20, 2000
Posts: 11
First your code should be:
if( document.forms[0].LId.value =="" &&
document.for[0].PW.value =="" )
{
alert( "you must enter valid Id and Password " )
document.forms[0].LId.focus()
}
else
document.forms[0].submit();
second, add link to the button (better use image) :
<a href="javascript:validate()"><img src="*.gif"></a>
You can't use submit type.
Satish Kasala
Greenhorn

Joined: Dec 19, 2000
Posts: 16
Hi padmashree,
You have to return false when LID or PWD are blank in your javascript and also modify the onclick method call to return the boolean value of the validation. Modify the code as given below and it should work.
if( document.forms[0].LId.value =="" &&
document.for[0].PW.value =="" )
{
alert( "you must enter valid Id and Password " )
document.forms[0].LId.focus()
return false;
}
else
{
return true;
}
<INPUT TYPE="SUBMIT" VALUE="Login" onclick = 'return validate( this )'>
Satish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onclick event(alert)