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
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validating forms and this piece of code does not work. Could you please tell me why?

    I am validating forms in JavaScript, and It's just not working. I have tried to figure it out myself, but I can't. The spaces between the forms are where the break tags are.

    <form name = "check" >
    First Name*:
    <input type="text" name="First Name" maxlength="15"/>




    Last Name*:
    <input type="text" name="Last Name" maxlength="15"/>




    Email*:
    <input type="text" name="Email"/>




    Contact Number:
    <input type="text" name="contact number"/>




    Message*:


    <textarea name="Enquiries" rows="10" cols="50">
    </textarea>





    <input type="checkbox" name="pricing"> I would like to find out the pricing of a particular painting.</input>


    <input type="checkbox"> I am asking a question.</input>



    <input type="submit" name="Send" onClick = "check()"/>

    </form>

    <script type = "text/javscript">

    function check(){
    if(document.check.pricing.checked){
    alert("OIIIIIII!");
    }
    else{
    alert("not checked");
    }
    }

    </script>


    P.S.
    If you know any good places to learn Javascript, please post them with your answer

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Don't attach an onclick to the submit button. Use onsubmit on the form tag itself and have the JavaScript return true or false depending on whether or not the form should be submitted.

    Don't use alert - it is intended only for debugging.

    See the orange link in my signature for a series of several hundred JavaScript tutorials.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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