Web Analytics Made Easy -
StatCounter how to parse in javascript - CodingForum

Announcement

Collapse
No announcement yet.

how to parse in javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to parse in javascript

    hello just wanna ask some help or advice.

    This code allow not to accept some special character. It only accept (numbers from 1 to 5 and a dot (.) ) This is actually a grade inputs.

    I wanted that the text field would only accept the following grades

    1.0
    1. 25
    1.50
    1.75
    2.0
    2.25
    2.50
    2.75
    3.0
    5.0

    PHP Code:
    <html>
    <
    head>
    <
    script language="Javascript">

        function 
    grades (e)
    {
        var 
    key window.event e.keyCode e.which;
        var 
    keychar String.fromCharCode(key);
        if(
    keychar == "0" || keychar == "1" ||keychar == "2" ||keychar == "3" ||keychar == "4" ||keychar == "5" || keychar == "." || key=="8" || keychar=="7")
            return 
    true;
        else return 
    false;
    }
    </
    script>
    </
    head>
    <
    body>
        <
    form>
            <
    input type="text" onkeypress="return onKeyPressBlockNumbers(event);" />
        </
    form>
    </
    body>
    </
    html
    anyone could give a suggestions on how to do this.

  • #2
    grade = document.forms.textboxName.value;
    if (grade == 1.0 || grade == 1.25 || grade == 1.50 ..........etc.
    {
    return true
    }
    else
    {
    alert "Invalid grade score - please enter it again")
    document.forms.textboxName.value == "";
    document.forms.textboxName.focus();
    return false;
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      You'll need to find a function that will convert the textbox inputs from a string to a number. Since this seems like an assignment I'll leave it up to you do that.
      ||||If you are getting paid to do a job, don't ask for help on it!||||

      Comment

      Working...
      X