Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums . You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
December 23rd, 2005, 02:41 PM
Registered User
Join Date: Dec 2005
Location: Sunrise Beach, MO, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
login script: user can't hit "return" for login
Hi, I am very new to
js and am using a simple login script I found at
www.laughland.biz . I needed this script to do 2 things it did't:
setfocus on the username field
allow the usesr to hit return after entering their pw and be logged in.
I got the first one, but can't for the life of me get the second.
Here's the code block I'm assuming this function would be in:
function BuildPanel() {
document.write('<form name="logon"><table align="center" border="0"><tr><td align="center">');
document.write('
Username: </td>');
document.write('<td>
<input type="text" name="username" size="20"> </td></tr>');
document.write('<tr><td align="right">
Password: </td>');
document.write('<td>
<input type="password" name="password" size="20"> </td></tr>');
if(imgSubmit == ""){
document.write('<tr><td align="center" colspan="2"><p><input type="button" name="Logon" value="Logon" onClick="login(username.value,password.value)" onKeyPress="login(username.value,password.value)"> ');
} else {
document.write('<tr><td align="center" colspan="2"><p><input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)">');
}
if(imgReset == ""){
document.write('<input type="reset" value="Reset" name="Reset">');
} else {
document.write('<input type="image" src="'+imgReset+'" name="Reset" onclick="logon.reset();">');
}
document.write('</p></td></tr></table></form>');
}
function setfocus() {
document.logon.username.focus();
}
K. Dawn Merrill
__________________
K. Dawn Merrill
December 24th, 2005, 01:49 PM
Authorized User
Join Date: Dec 2005
Location: Bangalore, , India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Dawn,
Try doing this in your javascript :
if(imgSubmit == ""){
document.write('<tr><td align="center" colspan="2"><p><input type="submit " name="Logon" value="Logon" onClick="login(username.value,password.value)" onKeyPress="login(username.value,password.value)"> ');
}
Note the type of the input. A submit button will automatically get fired when you
hit the enter button.
________
Adarsh
December 29th, 2005, 10:46 AM
Registered User
Join Date: Dec 2005
Location: Sunrise Beach, MO, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
HI Adarsh, and thanks for the information. I tried this & while it DOES allow the user to simply hit enter, it just returns to the same page & resets it to blank fields instead of going on to the next page. What am I doing wrong here? The only value I changed was the input type="submit"
Thanks, Dawn
K. Dawn Merrill
January 16th, 2006, 04:21 AM
Friend of Wrox
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Dawn,
Now that it's a submit button, when the user presses enter the browser goes to the "action" URL defined in your <form> element. To prevent this from happening (and to just run the login() javascript), change the following code
onClick="login(username.value,password.value)"
to this:
onClick="login(username.value,password.value); return false"
This should abort the default submit action and let login() set the window location to the URL you're expecting.
Let me know how it works!
Jon Emerson
Computer Scientist
Adobe Systems, Inc.
http://www.jonemerson.net/
January 16th, 2006, 04:55 PM
Registered User
Join Date: Dec 2005
Location: Sunrise Beach, MO, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jon, that's perfect! Thanks so much. Now I have one more question: I lose my setfocus if the user hits reset. Any ideas?
Thanks again, Dawn
K. Dawn Merrill
January 16th, 2006, 06:07 PM
Friend of Wrox
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
What form element do you want focused after reset is clicked?
Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
January 17th, 2006, 09:40 AM
Registered User
Join Date: Dec 2005
Location: Sunrise Beach, MO, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I would like it to go back to "username" after reset is clicked. Thanks for your help!
Dawn
K. Dawn Merrill
January 17th, 2006, 11:15 AM
Friend of Wrox
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Dawn,
I would do something like this:
Code:
<html>
<body>
<form action="test.html" method="get" name="logon">
<input type="text" name="username">
<input type="submit">
<input type="image" src="http://media.wiley.com/product_data/coverImage80/28/07645590/0764559028.jpg"
onclick="document.logon.reset(); document.logon.username.focus(); return false">
</form>
</body>
</html>
You might want to move the onclick() code into its own function -- but this shows the basic idea.
Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
January 17th, 2006, 05:27 PM
Registered User
Join Date: Dec 2005
Location: Sunrise Beach, MO, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Jon, I'll give that a try. Today is Friday for me, but I'll probably try it from home over my "weekend". I'll let you know how it works!
Thanks Again, Dawn
K. Dawn Merrill
July 12th, 2006, 04:28 AM
Registered User
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi
I'm using the exact same login script, but I am new to this and I can't get make the setfocus work.
Besides the
function setfocus() {
document.logon.username.focus();
}
do I need to add anything to the html, etc.?
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off