Click to See Complete Forum and Search --> : enter key


melcooper
08-18-2003, 12:41 AM
Hey,
Below is the script that I am using - I am not really very good with javascript, but I am having trouble adding a feature to make the password form work when the enter key is pressed - at the moment it only works when you click the button.

Cheers, Help appreciated. Melissa


<script language="javascript">
<!-- This version: Hostroute.com -->
<!-- Based on FTP log in by: Reinout Verkerk -->
<!-- Web Site: http://www.hostroute.com/script_htaccess.html -->

<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
if (username && password && server) {
var htsite = "http://" + username + ":" + password + "@" + server;
window.location = htsite;
}
else {
alert("Please enter your username and password.");
}
}
// End -->
</script>


#this is the body of the page - note the hidden form field "server" this needs to be the address of your password protected directory.

<form name=login>
<table width=250 border=1 cellpadding=3>
<tr>

<td colspan=2 align=center>
<h2><b>Logon to secure area!
<input type="hidden" name="server" value="www.domain.com/secure/">
</b></h2>
</td>
</tr>
<tr>
<td>Username:</td>
<td>
<input type=text name=username size=20>
</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(this.form)" name="button">
</td>
</tr>
</table>
</form>

Nevermore
08-18-2003, 02:43 AM
Try this:

<script language="javascript">
<!-- This version: Hostroute.com -->
<!-- Based on FTP log in by: Reinout Verkerk -->
<!-- Web Site: http://www.hostroute.com/script_htaccess.html -->

<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
if (username && password && server) {
var htsite = "http://" + username + ":" + password + "@" + server;
window.location = htsite;
}
else {
alert("Please enter your username and password.");
}
}
// End -->
</script>

<form name='login' onsubmit="Login('login')">
<table width=250 border=1 cellpadding=3>
<tr>

<td colspan=2 align=center>
<h2><b>Logon to secure area!
<input type="hidden" name="server" value="www.domain.com/secure/">
</b></h2>
</td>
</tr>
<tr>
<td>Username:</td>
<td>
<input type=text name=username size=20>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type=password name=password size=20>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value="Login!" name="button">
</td>
</tr>
</table>
</form>