Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 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
Default 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
Reply With Quote
  #2 (permalink)  
Old 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
Default

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
Reply With Quote
  #3 (permalink)  
Old 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
Default

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
Reply With Quote
  #4 (permalink)  
Old 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
Default

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/
Reply With Quote
  #5 (permalink)  
Old 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
Default

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
Reply With Quote
  #6 (permalink)  
Old 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
Default

What form element do you want focused after reset is clicked?

Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
Reply With Quote
  #7 (permalink)  
Old 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
Default

I would like it to go back to "username" after reset is clicked. Thanks for your help!

Dawn

K. Dawn Merrill
Reply With Quote
  #8 (permalink)  
Old 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
Default

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/
Reply With Quote
  #9 (permalink)  
Old 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
Default

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
Reply With Quote
  #10 (permalink)  
Old July 12th, 2006, 04:28 AM
rkn rkn is offline
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.?




Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
login script jstewie Javascript How-To 1 July 13th, 2005 12:52 PM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM
Login Script natmaster PHP How-To 10 June 19th, 2003 03:50 PM



All times are GMT -4. The time now is 07:54 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.