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>

  Re: User input validation  shams_khan1 at 17:56 on Sunday, October 12, 2008
 

give the if condition and put while loop in else statements try it out








CodeToad Experts

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








Recent Forum Threads
• Very slow inserts using SqlCommand.ExecuteNonQuery()
• Re: Problem 1 - Email ids conversion code
• Re: vector
• combined 3 functions that do the same thing
• Re: Finding data in hash
• Re: login logout ...
• Visual Basic
• Re: dynamic crystal report generation
• sorting 2 arrays


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