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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Stuck on my Javascript

    I am working on a javascript survey also using CSS. and i am trying to make it recognize proper names, to check the name and give an alert based on it. Using regexes to check for a proper zip code between 5 or 4 digits and to accept an age only up to 110, if an older age is entered an error message will be given.

    My page doesnt work as well as id like it to, can anyone help fix it or give suggestions?

    <HTML>
    <Head>
    <p> Survey for December
    <link rel="stylesheet" type="text/css"
    href="test.css" />
    <script language="JavaScript" type="text/javascript">

    Function name(dog) {
    with(window.document.forms.December)
    {
    reg3=/\d/g;
    if(reg3.test(dog.value))
    {
    alert('only use letters');
    }



    </script>
    </head>
    <body>
    <form action="" method=post name=December id=December >
    </form>
    <p>
    What is your first name?
    <input id=fname onblur=name(this) name=firstname>
    <p>
    What is your last name?
    <input name="txtlname" type="text">
    </p>
    <p>
    What is your age?
    <input name="txtlname" type="text">
    </p>
    <p>
    What is your zip code?
    <input name="txtlname" type="text">
    </p>
    </form>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rename your function from name to check_name and close the {'s youve opened. plus you dont really need
    the with stament

    Code:
    function check_name(dog) {
      reg3=/\d/g;
      if(reg3.test(dog.value))
        alert('only use letters');
    }
    Code:
    <input id=fname onblur="check_name(this)" name="firstname">
    http://demo.vegui.org - vegUI AJAX framework
    http://www.landsofkazram.com - browser based graphical MMORPG


  •  

    Posting Permissions

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