I have a Javascript function that uses Internet Explorer to open a window that prompts a user for his login ID, password, and target server, and displays a “Submit” button. It works, but it doesn’t do anything when the Enter key is pressed, only when the “Submit” button is clicked. I tried the usual things like adding an action attribute to the form tag and changing “<input type=’button’…” to “<input type=’submit’…”, but nothing I’ve tried seems to work. Can anyone tell me what I should do to make the function submit its values when the Enter key is pressed as well as when the “Submit” button is clicked? Thanks in advance to all who respond. Here’s a small demo containing the function:
[CODE]True = 1;
False = 0;
aryServers = Array( “server1”, “server2”, “server3”, “server4” );
strDefaultServer = “server2”;
objWShell = new ActiveXObject( “WScript.Shell” );
strLocalUser = objWShell.ExpandEnvironmentStrings( “%USERNAME%” );
strPassword = PasswordBox( “Enter Credentials” );
WScript.Echo( “Login ID: ” + strLoginID + “nPassword: ” + strPassword +
“nServer: ” + strServer );
WScript.Exit;
// ===========================================================================
function PasswordBox( strIETitle ) {
objIE = new ActiveXObject( “InternetExplorer.Application” );
objIE.FullScreen = False;
objIE.AddressBar = False;
objIE.MenuBar = False;
objIE.StatusBar = False;
objIE.ToolBar = False;
objIE.RegisterAsDropTarget = False;
objIE.Navigate(“about:blank”);
strLoginID = strLocalUser;
do {
WScript.Sleep( 100 );
} while ( ! objIE.ReadyState == 4 );
objIE.document.parentWindow.resizeTo( 400, 300 + 70 );
objIE.document.parentWindow.resizeTo( 400, 200 + 70 );
objIE.document.parentWindow.moveTo(
objIE.document.parentWindow.screen.width / 2 – 200,
objIE.document.parentWindow.screen.height / 2 – 200 );
objIE.document.writeln( “<html>” );
objIE.document.writeln( “<head>” );
objIE.document.writeln( “<title>” + strIETitle + “</title>” );
objIE.document.writeln( “<style type=’text/css’>” );
objIE.document.writeln( “<!–” );
objIE.document.writeln( “.fixed { font-family:courier new, monospace }” );
objIE.document.writeln( “–>” );
objIE.document.writeln( “</style>” );
objIE.document.writeln( “</head>” );
objIE.document.writeln( “<body bgcolor=Silver>” );
objIE.document.writeln( “<center>” );
objIE.document.writeln( “<form>” );
objIE.document.writeln( “<b>” + strIETitle + “</b><p>” );
objIE.document.writeln( “<table>” );
objIE.document.writeln( “<tr><td colspan=2 align=left>” );
objIE.document.writeln( “Enter your username and password:<br>” );
objIE.document.writeln( “</td></tr><tr><td valign=top>” );
objIE.document.writeln( “Username: ” );
objIE.document.writeln( “</td><td>” );
objIE.document.writeln( “<input id=’userid’ size=20 class=’fixed’ ” +
“value='” + strLoginID + “‘>” );
objIE.document.writeln( “</td></tr><tr><td valign=top>” );
objIE.document.writeln( “Password: ” );
objIE.document.writeln( “</td><td>” );
objIE.document.writeln( “<input type=’password’ id=’passwd’ size=20 class=’fixed’><p>” );
objIE.document.writeln( “</td></tr><tr><td valign=top>” );
objIE.document.writeln( “Remote Host: ” );
objIE.document.writeln( “</td><td valign=top>” );
objIE.document.writeln( “<select id=’server’><br>” );
intLen = aryServers.length;
for ( intI = 0; intI < intLen; intI++ ) {
if ( strDefaultServer == aryServers[ intI ] ) {
objIE.document.writeln( “<option value='” + aryServers[ intI ] +
“‘ selected>” + aryServers[ intI ] + “<br>” );
} else {
objIE.document.writeln( “<option value='” + aryServers[ intI ] +
“‘>” + aryServers[ intI ] + “<br>” );
}
}
objIE.document.writeln( “</select>” );
objIE.document.writeln( “</td></tr>” );
objIE.document.writeln( “</table>” );
objIE.document.writeln( “<p>” );
objIE.document.writeln( “<input type=’button’ value=’Submit’ id=’but0′ ” +
“onclick=”submitted.value=’DONE’;”>” );
objIE.document.writeln( “<input type=’hidden’ id=’submitted’ value=”>” );
objIE.document.writeln( “</form>” );
objIE.document.writeln( “</center>” );
objIE.document.writeln( “</body>” );
objIE.document.writeln( “</html>” );
objIE.document.parentWindow.document.body.scroll=”no”;
objIE.document.parentWindow.document.body.style.borderStyle = “outset”;
objIE.document.parentWindow.document.body.style.borderWidth = “3px”;
objIE.document.getElementById( “passwd” ).focus();
objIE.Visible = True;
objWShell.AppActivate( strIETitle );
blnPwdBoxWait = ”;
try {
do {
WScript.Sleep( 100 );
if ( objIE.Visible ) {
blnPwdBoxWait = objIE.document.getElementById( “submitted” ).value;
}
} while ( blnPwdBoxWait==” );
} catch( err ) {
WScript.Echo(‘ERROR: ‘ + err.message);
blnPwdBoxWait == ‘DONE’;
}
strLoginID = objIE.document.getElementById( “userid” ).value;
strPassword = objIE.document.getElementById( “passwd” ).value;
strServer = objIE.document.getElementById( “server” ).options( objIE.document.getElementById( “server” ).selectedIndex ).text;
objIE.Visible = False;
objIE.Quit();
objIE = null;
return strPassword;
}