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

    Need help in authorising form elements

    Hi, just wondering if someone can help me with a small problem. I have a form on my website that I want to confirm the user has ticked all the boxes before clicking on the Submit button. The submit button must then load another web page.

    I did find a tutorial on Java Script Kit, but haven't completely worked out how to apply it to my page. Code is as follows

    Code:
    <script type="text/javascript">
    <!--
    function validate(){
    if ((document.agree.chk_18.value=="")||
    (document.agree.chk_police.value=="")||
    (document.agree.chk_damages.value=="")||
    (document.agree.chk_agree.value=="")){
    .alert ("You must fill in all of the required .fields!")
    .return false
    .}
     else
     return true
    }
    //-->
    </script>
    As I want the boxes to be ticked, is this script checking that they are unticked? Should I have a space between the double quotes? And how do I get the Submit button named btn_agree to load the next page? ATM the button is loading the page before the check is taking place.

    Form Code:
    Code:
    <form name="agree" id="agree" method="post" action="x-rated3.htm" onsubmit="return validate()">
    					  <table width="85%"  border="0">
                            <tr>
                              <td><input name="chk_18" type="checkbox" id="chk_18" value="checkbox" /></td>
                              <td>I am over 18 or legal age in my jurisdiction to view or access adult material. </td>
                            </tr>
                            <tr>
                              <td><input name="chk_police" type="checkbox" id="chk_police" value="checkbox" /></td>
                              <td>I am not a member of the police force in any state or nationality.</td>
                            </tr>
                            <tr>
                              <td><input name="chk_damages" type="checkbox" id="chk_damages" value="checkbox" /></td>
                              <td>I do not hold the owner of this website liable for any damages whatsoever in accessing the material on this site. </td>
                            </tr>
                            <tr>
                              <td><input name="chk_agree" type="checkbox" id="chk_agree" value="checkbox" /></td>
                              <td>I have read and agree with all the above. </td>
                            </tr>
                            <tr>
                              <td><input name="btn_agree" type="submit" id="btn_agree" value="Agree" /></td>
                              <td>&nbsp;</td>
                            </tr>
                          </table>
    			      </form>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try
    Code:
    <script type="text/javascript">
    
    function validate(){
    if (document.agree.checked==false || 
     document.agree.chk_police.checked==false||
     document.agree.chk_damages.checked==false||
     document.agree.chk_agree.checked==false){
    alert ("You must fill in all of the required .fields!")
    return false;
    }
     else
     return true;
    }
    
    </script>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Twisties34 (06-25-2009)

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Beautiful. Works perfectly now. Thankyou

    *huggles*


  •  

    Posting Permissions

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