Forum Moderators: open

Message Too Old, No Replies

Pressing Enter to Submit Password/Form

I need help.

         

blaze_sd

4:21 am on Jan 15, 2010 (gmt 0)

10+ Year Member



Can somebody please help me? I want to be able to submit a password/form by clicking enter/return on the keyboard.

Here's the code:

<html>
<head>
<title></title>
<script language = javascript>
function regulate()
{

if(document.pass.pass.value == 'apassword') {
window.location = "wgw.html";
}
else
{
window.location = "gtfo.html";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css">

<!--
body,td,th {
color: #000000;
}
body {
background-color: #000000;
background-image: url(an image url);
background-repeat:no-repeat;
background-position:top center;
}
--></style> <!--
center div { display:none!important; }
}
-->
</head>
<body spellcheck="false">
<form name="pass">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;</p>
<div align="center">
<p><input type="password" name="pass" /></p>
</div>
<div align="center">
<p>&nbsp;<img src="http://example.com/img444/5631/loginau.png" alt="Click Me!" onclick="javascript:regulate();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
</div>
</form>
<p>&nbsp;</p>
</body>
</html>

Thanks,
Blaze

[edited by: tedster at 4:32 am (utc) on Jan. 15, 2010]
[edit reason] fix side-scroll [/edit]

Fotiman

2:26 pm on Jan 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!

1. Your form lacks an action. Give it an action (where it will be submitted to).
2. Give your form a submit button, or input type="img" instead of <img>. Then the default browser behavior should work properly, submitting the form when Enter is pressed.

Hope that helps.

Seb7

2:58 pm on Jan 15, 2010 (gmt 0)

10+ Year Member



Make this amendment for it work:
<form name="pass" onsubmit="regulate(); return false">

I would also change the form name as not conflict with the field name.

You really should use server side password checking as to have some security and man those &nbsp are ugly!