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
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Javascript form help

    Hello I have created a simple form which validates certain fields. However I would like it to make it validate the drop down boxes ignoring the first field (choose your...) I would also like it to validate the check box both in the same way it validates the other things. There are no errors with the code.

    Thanks in advance for your help
    Here is my code:

    Code:
    <head>
    
    <script language="JavaScript">
    
    <!-- Begin
    function checkFields() {
    missinginfo = "";
    if (document.form.name.value == "") {
    missinginfo += "\n     -  Name";
    }
    if ((document.form.from.value == "") || 
    (document.form.from.value.indexOf('@') == -1) || 
    (document.form.from.value.indexOf('.') == -1)) {
    missinginfo += "\n     -  Email address";
    }
    if(document.form.phone.value == "") {
    missinginfo += "\n     -  Phone Number";
    }
    if(document.form.address.value == "") {
    missinginfo += "\n     -  Address";
    }
    if(document.form.post.value == "") {
    missinginfo += "\n     -  Post Code";
    }
    if(document.form.translation.value == "") {
    missinginfo += "\n     -  Translation";
    }
    if (document.form.terms.checked == false) {
    missinginfo += "\n     -  Terms and Conditions";
    }
    if (missinginfo != "") {
    missinginfo ="\n" +
    "You failed to correctly fill in your:\n" +
    missinginfo + "\n" +
    "\nPlease re-enter and submit again";
    alert(missinginfo);
    return false;
    } else {
    	self.setTimeout('pageLoader()',5000);
    	return true;
    }
    }
    function pageLoader() {
    	window.location.href = 'http://www.google.com';
    }
    //  End -->
    </script>
    </head>
    
    <body>
    
    <form name=form onSubmit="return checkFields()" form method="POST" enctype="text/plain" action="mailto:myaddress@mydomain.com">
    
    Name: <br><input type=text name="name" size=30>
    <p>
    E-mail: <br><input type=text name="from" size=30>
    <p>
    Phone Number: <br><input type=text name="phone" size=30>
    <p>
    Address: <br><textarea rows=4 cols=40 name="address"></textarea><p>
    <p>
    Post Code: <br><input type=text name="post" size=30>
    <p>
    Payment Method:<br><select name="payment"> <OPTION value="0">Please pick your Payment method:</OPTION> 
    <OPTION value="1">Credit Card</OPTION> <OPTION value="2">Cheque</OPTION></select>
    <p>
    Delivery Method:<br><select name="delivery"><OPTION value="0">Please pick your Delivery method:</OPTION>  <option value"1">Email</option> <option value"2">Post</option> <option value"3">Fax</option></select>
    <p>
    Translation: (Copy and paste your translation into here) <br><textarea rows=3 cols=40 name="translation"></textarea><p>
    <p>
    Extra Info: <br><textarea rows=3 cols=40 name="comments"></textarea><p>
    <p>
    Terms and Conditions: <br><textarea rows=4 cols=40 name="terms" readonly="readonly">
    In this document: No part of any numbered clause shall be read separately from any other part. Section headings are provided for convenience of reading only and shall be ignored for the purposes of ascertaining meaning. 
    </textarea><p>
    <p>
    I Accept the Terms and Conditions: &nbsp;&nbsp; <input type="checkbox" name="terms" value="checkbox">
    <p>
    <p><input type=submit name="submit" value="Submit">
    
    
    </form>
    And if it's any help this is the block of code which will need editing in order to fit my needs

    Code:
    if(document.form.fieldname.value == "") {
    missinginfo += "\n     -  Whatever";
    }
    Thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You can use the selectedIndex to validate your drop down boxes:
    Code:
    if(document.form.payment.selectedIndex <= 0) {
    missinginfo += "\n     -  Payment";


  •  

    Posting Permissions

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