Logging on to a VMS host

In this example, a VT terminal session is embedded in the browser window, and JavaScript is used to log on to the host computer. Two <form> fields on the web page are used to get the user's name and password before performing the logon. A related example shows a VBScript version of this script for Internet Explorer.To use this example, you must change the hostURL parameter in the <applet> tag below to a host appropriate for your network.

<html>
<head>
<title>Sample Logon Script for VT (JavaScript)</title>
<script language="JavaScript">
<!--
    var uname;
    var pword;
    var api = null;

    /*
       The jsapiInitialized function is called by Reflection
       when it has finished its initialization. Reflection
       passes the function a reference to the JavaScript API.
    */
    function jsapiInitialized( jsapi )
    {
       api = jsapi; 
    }

    /*
       This is the main function that performs the logon tasks.
    */
    function handleLogonButton()
    {
        // Validate the username and password.
        if ( validateInputs() )
        {
            doConnect();
        }
    }

    /*
       This function checks for a username and password, and if either is
       not present, displays an alert message.
    */
    function validateInputs()
    {
        uname = document.LogonForm.Username.value;
        pword = document.LogonForm.Password.value;
        if ( uname == "" )
        {
            alert( "You must enter a Username to log on!" );
            document.LogonForm.Username.focus();
            return false;
        }
        if ( pword == "" )
        {
            alert( "You must enter a Password to log on!" );
            document.LogonForm.Password.focus();
            return false;
        }
        return true;
    }
    
    /*
       This function starts the actual logon tasks. It determines if the session
       is connected, and if so, calls the function that finds the Username and 
       Password prompts on the display and transmits the user's data.
    */
    function doConnect()
    {
        // If there's no connection, try to connect.
        if ( !api.isConnected() )
        {
            self.status = "Connecting...";
            api.connect();
        }
        else
        {
            alert( "You're already connected!" );
            return;
        }

        // Wait 5 seconds for the Username prompt.
        self.status = "Waiting for Username prompt.";
        if ( !api.waitForString( "Username:", 5000 ) )
        {
            alert( "Unable to find Username prompt. The script will stop, " + 
                   "but you may continue manually." );
            return;
        }
        
        // Username prompt was found, so transmit the user's username,
        // followed by a carriage return. The octal representation of the
        // carriage return character--which is decimal 13--is used. You 
        // can also use the carriage return symbol \r or the hex value
        // \x0D. You CANNOT use the decimal value 13, because this will be
        // converted to a string and appended to the username.
        api.transmitString( uname + "\015" );
        
        // Wait 5 seconds for the Password prompt.
        self.status = "Waiting for Password prompt.";
        if ( !api.waitForString( "Password:", 5000 ) )
        {
             alert( "Unable to find Password prompt. The script will stop, " + 
                   "but you can try completing the logon manually." );
            return;
        }

        // Password prompt was found, so transmit the user's password,
        // followed by a carriage return. As above, the octal
        // representation of the carriage return character is used.
        api.transmitString( pword + "\015" );
        
        // Done with logon, so display final status message, and set
        // focus to the terminal display.
        self.status = "Ready to proceed.";
        api.requestDisplayFocus();
    }
// -->
</script>
</head>
<body>
<h1>Reflection for the Web -- VT Logon</h1>
<p>
<!--
   Create a basic VT applet on the page, but don't connect until
   the user fills in the username and password information. 
   To use this example, change the hostURL parameter to one 
   appropriate for your network.
-->
<applet mayscript name="VT"
        codebase="./ex/"
        code="com.wrq.rweb.Launcher.class"
        width="600" height="400"
        archive="Launcher.jar">
    <param name="hostURL" value="telnet://accounts">
    <param name="autoconnect" value="false">
    <param name="frame" value="false">
    <param name="launcher.sessions" value="VT">
    <param name="preloadJSAPI" value="true">
</applet>
</p>
<!--
   Use <form> items to accept the Username and Password, and to create
   a Logon button.
-->
<form name="LogonForm">
<p>Username: <input type="text" name="Username" default size="25"></p>
<p>Password: <input type="password" name="Password" size="25"></p>
<p><input type="button" name="Logon" value="Logon" onClick="handleLogonButton()"></p>
</form>
</body>
</html>