Use return Key to submit

A

Anthony

I have a form on a web page that requires to click on a button to
submit the information. I have two questions about changing this form:
1. Is there a way that I can change the script so that the form can be
submitted by hitting the enter key?
2. Is there a way that I can have the Username and Password boxes
cleard after the form is submitted?

You probably don't need the code for the form as it is pretty basic but
here it is just in case. Thanks.

<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size="+2"><b>Bombers Only
Area!</b></font></center></td></tr>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=password name=password
size="20"></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!"
onClick="Login()"></td></tr>
</table>
</form>
 
Z

zero0x

Anthony napísal(a):
I have a form on a web page that requires to click on a button to
submit the information. I have two questions about changing this form:
1. Is there a way that I can change the script so that the form can be
submitted by hitting the enter key?
2. Is there a way that I can have the Username and Password boxes
cleard after the form is submitted?

You probably don't need the code for the form as it is pretty basic but
here it is just in case. Thanks.

<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size="+2"><b>Bombers Only
Area!</b></font></center></td></tr>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=password name=password
size="20"></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!"
onClick="Login()"></td></tr>
</table>
</form>

the easiest way is to add onsubmit="Login(); return false;"

to erase values from form, just add inputobj.value="" to Login()
function.
 
A

Anthony

I have another question for which I will give you some more background
info. I am using a external JS script that is called from a source
file on my website. This is the code:

function Login() {
var username=document.login.username.value.toLowerCase();
var password=document.login.password.value.toLowerCase();

for (i=0; i<userData.length; i++) {
if (username==userData [0] && password==userData [1]){
window.open(userData
[2],"blank","toolbar=no,width=540,height=250,top=0,left=0");
return true;
}
}
alert("Invalid Login!");
}

I would like the window in the above function to open on "top" of the
login page of my website. When I use the input type=button it works
like I want but I HAVE to click on the Login! button which I am trying
to avoid. When I change to input type=submit, the new window opens up
briefly and then "hides" behind the page that holds the form. How do I
fix this or is it even possible? Thanks for taking the time to help.
 
A

ASM

Anthony a écrit :
I have another question for which I will give you some more background
info. I am using a external JS script that is called from a source
file on my website. This is the code:

What is your site ?
With this code it's really too easy to log under a stolen pseudo ! !
We only need to get userData ... :-(
function Login() {
var username=document.login.username.value.toLowerCase();
var password=document.login.password.value.toLowerCase();

for (i=0; i<userData.length; i++) {
if (username==userData [0] && password==userData [1]) {
window.open(userData
[2],"blank","toolbar=no,width=540,height=250,top=0,left=0");


return false;
}
}
alert("Invalid Login!");

return false;
}

I would like the window in the above function to open on "top" of the
login page of my website.

What 'top of page' does mean for you ?
Don't you mean 'to open a popup' ? (at front of the main window)
In JS 'top' is the main page in a framed page.
When I use the input type=button it works
like I want but I HAVE to click on the Login! button which I am trying
to avoid.

if you have :
When I change to input type=submit, the new window opens up
briefly and then "hides" behind the page that holds the form.

If you ask to open a new window via submit button you must avoid action
of the form,
this is accomplished by form's onsubmit which returns 'false'.


If one of the text fields has focus, pressing Enter key will submit,
it's a normal feature
(NC4 did so if the form has only one text field)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top