www.webdeveloper.com
Results 1 to 5 of 5

Thread: Need some help with error handling..

  1. #1
    Join Date
    Apr 2012
    Posts
    14

    Need some help with error handling..

    Here is my assignment and I am a little confused. I barely know any JavaScript so this is kind of overwhelming.

    Write JS code that anticipates and handles an error for an expected numeric field. This code is executed on keypress, and the entered value is saved for you in a variable called enteredChar. Include the try block of JS statements needed to check if the character is not a number or a non-alphanumeric character, or if you throw an error message.

    Write a custom error handling JS function called processErrors that handles a custom error by assigning it to the onerror event handler. Include the block of JS statements needed to pass the arguments sent by the JS interpreter into the processErrors function, send an alert message with the agreements, return, and write the event handler that calls the processErrors function.
    Last edited by JavaMon; 04-06-2012 at 07:25 PM.
    Hoping to learn and understand JavaScript!

  2. #2
    Join Date
    Apr 2012
    Posts
    14
    Here is what I got for the first part tell me what I can change to fix it please
    <script type="text/javascript">
    function validateNumber(formObject) {
    try {
    var number = formObject.value;
    var numberCheck = ?
    if (numberCheck.test(number) = false)
    throw "One or more of the numbers
    you entered
    appear to be not valid.";
    }
    catch(numberError) {
    window.alert(numberError)
    return false;
    }
    return true;
    }
    </script>
    Last edited by JavaMon; 04-06-2012 at 06:47 PM.
    Hoping to learn and understand JavaScript!

  3. #3
    Join Date
    Apr 2012
    Posts
    14
    K so here is what I got now for the first question would this work

    <script type="text/javascript">
    function validateNumber(formObject) {
    var x=prompt("0","");
    try
    {
    if(x>10)
    {
    throw "er1";
    }
    else if(x<0)
    {
    throw "er2";
    }
    else if(isNaN(x))
    {
    throw "er3";
    }
    }
    catch(er)
    {
    if(er=="er1")
    {
    alert("Error: The value is too high");
    }
    if(er=="er2")
    {
    alert("Error: The value is too low");
    }
    if(er=="er3")
    {
    alert("Error: The value is invalid");
    }
    }
    </script>
    Hoping to learn and understand JavaScript!

  4. #4
    Join Date
    Apr 2012
    Posts
    14
    for the 2nd part it need to be like this
    <script>
    function handler(event) {
    alert(event);
    }
    </script>


    but I dont know what to do with that
    Hoping to learn and understand JavaScript!

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Quote Originally Posted by JavaMon View Post
    Here is what I got for the first part tell me what I can change to fix it please
    <script type="text/javascript">
    function validateNumber(formObject) {
    try {
    var number = formObject.value;
    var numberCheck = ? // here goes a regular expression - something like /[\d]{1,}/g;
    if (numberCheck.test(number) ==false)
    throw "One or more of the numbers
    you entered
    appear to be not valid.";
    }
    catch(numberError) {
    window.alert(numberError)
    return false;
    }
    return true;
    }
    </script>
    for the very first sight these 2 corrections must be done
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles