codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  User input validation  miamimarcus at 03:26 on Thursday, October 09, 2008
 

Hello, I'm new to this and trying to validate user input to do the following:

If the user enters something other than a 1 or 2, display an error message using the alert dialog box.
Prompt the user for a valid number.
For every value input, if the value entered is other than 1 or 2, keep looping until the user enters a correct value.
There should be a total of 10 valid inputs.

Here is my code so far:

<head>
<title>Analysis of Examination Results</title>
<script type = "text/javascript">
<!--
// initializing variables in declarations
var passes = 0; // number of passes
var failures = 0; // number of failures
var student = 1; // student counter
var result; // one exam result

// process 10 students; counter-controlled loop


while ( student <= 10 )

{
result = window.prompt( "Enter result (1=pass,2=fail)", "0" );


if ( result == "1" )
passes = passes + 1;
else
failures = failures + 1;

student = student + 1;

} // end while

// termination phase
document.writeln( "<h1>Examination Results</h1>" );
document.writeln(
"Passed: " + passes + "<br />Failed: " + failures );

if ( passes > 8 )
document.writeln( "<br />Raise Tuition" );
// -->
</script>
</head>
<body>
<p>Click Refresh (or Reload) to run the script again</p>
</body>
</html>








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  I Need Help
•  User input validation
•  Create a wrapper for a COM Dll
•  HashMaps
•  HashMaps
•  NEED HELP! Urgent
•  Re: Exciting Open Source Project in C++
•  Re: The Ballarat Airline Company (BAC)
•  Re: problem getting prompt window to work on IE


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008