Results 1 to 2 of 2

Thread: validate form

  1. #1
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default validate form

    Hi everyone, i have to validate a form for a client, i have it working apart from two sections.

    Do you require transportation? yes or no
    Do you require installation? yes or no

    when clicked yes a new div appears "divtxta", i need this div to be validated when yes is checked but not to be validated when no is checked.

    If anyone can help i would really appreciate it.

    <---------------------------
    Code:
    -------------------------------------->
    
    </SCRIPT>
    <!-- End DI Tracking Code -->
    <script language="JavaScript">
    function showhide(inval,divid)
    {
    if(inval=="yes")
    {document.getElementById(divid).style.visibility=" visible"}
    if(inval=="no")
    {
    document.getElementById(divid).style.visibility="h idden"
    document.contact.txta.value="Enter your reason here"
    }
    }
    
    function showhide(tranval,divid)
    {
    if(tranval=="yes")
    {document.getElementById(divid).style.visibility=" visible"}
    if(tranval=="no")
    {
    document.getElementById(divid).style.visibility="h idden"
    document.contact.txta.value="Enter your reason here"
    }
    }
    </script>
    
    </head>
    
    <body>
    
    <div id="container">
    <div id="wrapper">
    
    <div id="header">
    <!--[if IE]>
    <style>
    #header {width: 960px;}
    </style>
    <![endif]-->
    <img src="images/bottom-banner.gif" />
    <!-- <img src="images/site-shed-sales.jpg" width="117" height="83" /> -->
    </div>
    
    <div id="nav">
    <?php
    include('inc.nav.php');
    ?>
    </div>
    
    <div id="left">
    <h1 class="normal">Contact Site Shed Sales</h1>
    <br />
    To enquire about our products or services, please submit your details below and we will contact you shortly.
    <br />
    <br />
    <form name="contact" method="post" action="mail.php">
    
    <label>Name</label>
    <input type="text size="40" name="name" />
    <br />
    
    <label>Company / Organisation</label>
    <input type="text size="40" name="company" />
    <br />
    
    <label>Telephone</label>
    <input type="text size="40" name="phone" />
    <br />
    
    <label>Email</label>
    <input type="text size="40" name="email" />
    <br />
    
    
    <label>Building Interested in</label>
    <textarea rows="1" cols="40" name="interest"><?=$building?></textarea>
    <br />
    
    
    <label>Do you require transportation?</label>
    <input type="radio" name="tran" value="yes" onClick="showhide(this.value,'divtxta')">Yes
    <input type="radio" name="tran" value="no" onClick="showhide(this.value,'divtxta')">No
    <br />
    <div id="divtxta" style="visibility:hidden;">
    <textarea name="location" rows="3" cols="40">Please enter location</textarea>
    </div>
    
    
    
    <label>Do you require installation?</label>
    <input type="radio" name="in" value="yes" onClick="showhide(this.value,'divtxtatwo')">Yes
    <input type="radio" name="in" value="no" onClick="showhide(this.value,'divtxtatwo')">No
    <br />
    <div id="divtxtatwo" style="visibility:hidden;">
    <textarea name="sitedescription" rows="3" cols="40">Please enter site description</textarea>
    </div>
    
    
    
    <label>Any other information</label>
    <textarea rows="10" cols="40" name="additional"></textarea>
    <br />
    <br />
    
    <label></label>
    <input type="submit" name="submit" value="Send Enquiry" /><br />
    
    <div id='contact_errorloc' class='error_strings'></div>
    </form>
    <br />
    <br />
    
    
    <script language="JavaScript" type="text/javascript">
    //You should create the validator only after the definition of the HTML form
    var frmvalidator = new Validator("contact");
    frmvalidator.EnableOnPageErrorDisplaySingleBox();
    frmvalidator.EnableMsgsTogether();
    
    frmvalidator.addValidation("name","req","Please enter your Name.");
    frmvalidator.addValidation("name","maxlen=20", "Max length for Name is 20");
    frmvalidator.addValidation("name","alpha_s","Name can contain alphabetic chars only");
    
    frmvalidator.addValidation("company","req","Please enter your Company / Organisation.");
    frmvalidator.addValidation("company","maxlen=20"," For LastName, Max length is 20");
    
    frmvalidator.addValidation("email","maxlen=50");
    frmvalidator.addValidation("email","req");
    frmvalidator.addValidation("email","email");
    
    frmvalidator.addValidation("phone","minlen=10");
    frmvalidator.addValidation("phone","numeric");
    
    frmvalidator.addValidation("interest","Please enter the building interested in. ");
    frmvalidator.addValidation("interest","maxlen=40") ;
    
    frmvalidator.addValidation("location","req","Pleas e enter the site location. ");
    frmvalidator.addValidation("location","maxlen=40") ;
    
    frmvalidator.addValidation("sitedescription","req" ,"Please enter the site description. ");
    frmvalidator.addValidation("sitedescription","maxl en=40");
    
    
    </script>
    
    
    <-------------------------------
    ---------------------------------->




    I am also using a JavaScript to validate the form "gen_validatorv31.js"
    that i got from http://www.javascript-coder.com/html...lidation.phtml

    Many Thanks

  2. #2
    Join Date
    Apr 2006
    Location
    Brisbane
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Darren,

    why not use an onsubmit="extra_validation(contact)" in the form tag, then in this function check each radio set in turn to see if set to yes, if so, add in frmvalidator.addValidation("location","maxlen=250");

    Ok nevermind this I've just read the tutorial on your validation script. I'm guessing you haven't read it right the way through because it answers your question. Check this out: http://www.javascript-coder.com/html...n.phtml#custom
    Last edited by ill_comms; 07-15-2008 at 09:11 AM.

Bookmarks

Posting Permissions

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