Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Document Object Model?

    I have an internet form with many input boxes and I need to check most of them to see if they're numeric.

    I have written an isnumeric function and I realise I could type a line such as

    If (IsNumeric(document.getElementById( TagName ).value)) {
    return true
    else
    return false
    }



    for each one individually to test, but since there are hundreds of fields, I was wondering if there was an easier way of doing this

    Is there any way of looping through the elements (each input box) on my form?

    Any example code would be a great help.

    Many Thanks
    Dawn

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var inputs = document.forms[0].getElementsByTagName("input");
    for (i = 0; i < inputs.length; i++) {
    	if(inputs[i].type == "text") if(IsNumeric(inputs[i].value))
    		alert("input #" + i + " is numeric");
    	// false statement below
    }
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/JavaScript">
    function valid(f) {
    if (!/^\d*$/.test(f.value)) {
    alert("Only integer numbers allowed!");
    f.value = f.value.replace(/[^\d]/g,"");
    }
    } 
    </script>
    </head>
    <body>
    <input type="text" onkeyup="valid(this)">
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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