G
Geoff
As a newbie to javascript can someone tell me please how to pass a variable from HTML to Javascript?
I have the following script which works OK if I input to str from the "prompt" box, but I want to input from a one-line text box on an HTML page.
Thanks in advance.
Geoff.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<script type = "text/javascript">
// Input number
var str = null;
if ( str == null );
var str = prompt( "Enter number", "" );
var num2 = str.substr(0,3);
var res = +num2;
// Test for correctness
if(res == 123) alert ("This will work OK");
else
if(res == 124) alert ("This will work OK");
else
if(res == 128) alert ("This will work OK");
else
alert (" Unfortunately, this will not work");
</script>
</body>
</html>
I have the following script which works OK if I input to str from the "prompt" box, but I want to input from a one-line text box on an HTML page.
Thanks in advance.
Geoff.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<script type = "text/javascript">
// Input number
var str = null;
if ( str == null );
var str = prompt( "Enter number", "" );
var num2 = str.substr(0,3);
var res = +num2;
// Test for correctness
if(res == 123) alert ("This will work OK");
else
if(res == 124) alert ("This will work OK");
else
if(res == 128) alert ("This will work OK");
else
alert (" Unfortunately, this will not work");
</script>
</body>
</html>