+ Reply to Thread
Results 1 to 4 of 4

Thread: form validation w/Javascript

  1. #1
    surreal5335 is offline x10Hosting Member surreal5335 is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    28

    form validation w/Javascript

    I have email form created with the javascript validation already coded. When I click on the submit button no alert boxes pop to warn me I dont have the fields entered. Can anybody help me to get the JS to take action when the submit button is clicked?

    here is the page of code including the JS and email form:

    Code:
    <html>
    <head>
    
    <script type="text/javascript" language="JavaScript">
    
    
    //validating email address
        re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    
        function submitit(myform) {
    
        if (re.test(myform.emailaddr.value)) {
            return true
    }
        alert("invalid email address")
        myform.emailaddr.focus( )
        myform.emailaddr.select( )
        return false
    }
    
        function validform(emailaddrform) {
        if (emailaddrform.emailaddr1.value == "") {
        alert("You must enter an email address")
        emailaddrform.emailaddr1.focus( )
        return false
    
    }
        if (emailform.emailaddr1.value ! = emailform.emailaddr2.value) {
        alert("Entered email addresses did not match")
        emailform.emailaddr1.focus( )
        emailform.emailaddr1.select( )
        return false
        }
        return true
    }
    
    </script>
    </head>
    <body>
    <table border="1" width="100%">
    <tr>
    <td width="10%">
    <map name="homeleft" id="homeleft" align="left">
    <area shape="rect" coords="10, 10, 212, 219" href="index.html"/>
    <area shape="rect" coords="66, 253, 168, 303" href="realestatepost.html"/>
    <area shape="rect" coords="66, 342, 168, 391" href="graphics.html"/>
    </map>
    
    <img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/homeleft.png"  usemap="#homeleft" id="homeleft" hspace="10" vspace="10" align="center"><br>
    
    </td>
    <td width="80%">
    <!--home content--!>
    
    <img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/portfolioheader.png" hspace="10" vspace="10" align="center"><br/><br>
    <form method="post" name="emailform" action="emailform.php">
    <p class="legend">Contact via email</p>
    <fieldset id="conact">
    <label>Name: </label><input type="text" name="name" size="30"/><br/>
    <br>
    <label>Email:  </label><input type="text" name="emailaddr1" size="30"/><br/>
    <br>
    <label>Email:  </label><input type="text" name="emailaddr2" size="30"/><br/>
    <br>
    <label>Phone: </label><input type="text" name="phone" size="30"/><br/>
    <br>
    <label>Comments: </label><br><textarea name="comments" rows="10" cols="30">Please give me a brief description of the work you need done</textarea><br/>
    <br>
    <input type="submit" name="submit"><a href="thankyou.html"></a></button><br/>
    
    </td>
    <td width="10%">
    
    <map name="homeright" id="homeright" align="left">
    <area shape="rect" coords="37, 530, 191, 683" href="contact.html"/>
    </map>
    
    <img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/homeright.png"  usemap="#homeright" id="homeright" hspace="10" vspace="10" align="center"><br>
    </td>
    </tr>
    </body>
    </table>
    </html>
    Thanks a lot for your help

  2. #2
    bonzo meier is offline x10Hosting Member bonzo meier is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    47

    Re: form validation w/Javascript

    hi,

    you should add an onClick-action to the button field:
    change your code
    <input type="submit" name="submit"><a href="thankyou.html"></a></button><br/>

    to:
    <input type="submit" name="submit" onClick="validform('emailform');"><a href="thankyou.html"></a></button><br/>

    or something like that.

    success!
    bonzo

  3. #3
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: form validation w/Javascript

    "myform.emailaddr.value" this and others like it should have "document." infront of it.
    "document.myform.emailaddr.value";

    Also
    <input type="submit" name="submit"> should be
    <input type="button" name="submit" value="Send Email" onclick="submitit();" />
    Then on the emailform.php is where you include the thank you page. Otherwise if you click that link it will take you to the thankyou page without sending the email.

  4. #4
    lszanto is offline x10Hosting Member lszanto is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    23

    Re: form validation w/Javascript

    I'm sure you proberly know this but i'm just checking, make sure you have other validation on your website and don't rely on javascript. You can easily get around it and/or simply disable it.

+ Reply to Thread

Similar Threads

  1. Addon Domain PHP Form Error
    By rockee in forum Free Hosting
    Replies: 2
    Last Post: 04-02-2008, 06:53 PM
  2. Easy XHTML form validation using PHP
    By Xemnas in forum Tutorials
    Replies: 0
    Last Post: 01-08-2008, 04:29 AM
  3. Design a free form
    By gateway in forum Off Topic
    Replies: 1
    Last Post: 10-19-2007, 05:49 PM
  4. My php Form tutorial
    By WinGate in forum Tutorials
    Replies: 0
    Last Post: 08-20-2007, 08:14 PM
  5. A simple Visual Basic Login Form
    By Zenax in forum Tutorials
    Replies: 0
    Last Post: 03-13-2007, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers