Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Need help creating an error message

Results 1 to 2 of 2
Share This Thread →
  1. #1
    moneypenny001 is offline Registered User
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Need help creating an error message

    The code is suppose to if an number is not entered by the user that an error message stating that they must enter a number and allows them to try again. Can anyone help me to figure out where and what code I need to add?

    <script type="text/javascript" charset="UTF-8">
    var width = prompt( "Enter the width of a rectangle." )
    if ( isNaN(width) ) {
    alert("You must enter a number.");
    width;
    }
    var height = prompt( "Enter the height of a rectangle." )
    if ( isNaN(height)){
    alert("You must enter a number.");
    height;
    }
    var area = parseInt(width) * parseInt(height);

    alert( "The area of the rectangle is " + area);
    </script>

  2. #2
    coyote is offline Registered User
    Join Date
    Feb 2013
    Location
    Norfolk, UK
    Posts
    1
    Rep Power
    0
    One problem is that you left off semi-colons at the end of a couple of lines. Also, a couple of lines were redundant. But then that will only check that the user entered some text instead of a number. If you want to prevent them simply pressing "enter", you could check that the number isn't zero as well.
    Additionally, you'd presumably want to go back to the prompt until they'd entered a number. Something like this:

    Code:
    <script type="text/javascript" charset="UTF-8">
    var isValid = 0;
    while (isValid == 0) {
    	var width = prompt( "Enter the width of a rectangle." );
    	if ( isNaN(width) || width==0 ) {
    		alert("You must enter a number.");
    	} else {
    		isValid = 1;
    	}
    }	
    
    isValid = 0;
    while (isValid == 0) {
    	var height = prompt( "Enter the height of a rectangle." );
    	if ( isNaN(height) || height==0 ) {
    		alert("You must enter a number.");
    	} else {
    		isValid = 1;
    	}
    }	
    
    var area = parseInt(width) * parseInt(height);
    
    alert( "The area of the rectangle is " + area);
    </script>

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Advice on creating email message
    By trevi in forum Microsoft Access Help
    Replies: 3
    Last Post: June 21st, 2012, 12:54 AM
  2. Problems when creating an object cdo.message
    By sisuka in forum ASP Development
    Replies: 4
    Last Post: April 7th, 2006, 02:33 AM
  3. creating a help message from a command button
    By ddennis in forum Microsoft Access Help
    Replies: 1
    Last Post: April 30th, 2005, 06:41 PM
  4. Creating Message Box in the FORM of MS Access 2002
    By szms in forum Microsoft Access Help
    Replies: 7
    Last Post: July 6th, 2004, 09:48 AM
  5. creating error message
    By Steve Schofield in forum ASP Development
    Replies: 2
    Last Post: December 15th, 2000, 03:44 AM

ASP Free Advertisers and Affiliates