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
    Regular Coder
    Join Date
    Dec 2005
    Posts
    149
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Tick box to go next

    Hello Guys,

    I have a oscommerce store, for which i want to be able to make sure that if the tick box is not ticked then it will not go to the next page, so for example.

    customer clicks on finish to order, but gets a popup saying please tick the box, and if ticked, the page just goes normal

    THank you
    Tomorrow Could Be Your Day

  • #2
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello,
    There are a couple ways of doing this, some being with client side validation, and server side... And of course both!

    To check to see if they've "checked" the checkbox by either $_POST, or $_GET you need to do the following:

    Lets say in this example we've got the form, with the input field checkbox, and name of it as chkAgreeExample:

    Code:
    <form....>
    
    <input type="checkbox" name="chkAgreeExample" />
    
    </form...
    Now when the form is submitted, and you want the server side validation to pick it up do the following in PHP: This example I'm using $_POST superglobal, if you're submitting the form using $_GET use that instead of where I've written $_POST.

    PHP Code:
    if(isset($_POST))
    {
        
    /// other checks....

        #Lets check just for this option..
        
    if($_POST["chkAgreeExample"] == "ON")
        {
           
    # do magic here...
        
    }
        
    ///.... blah blah blah

    Now if you want to have a client side validation, you can capture the value of it by doing the following:

    Code:
    var checkBox = document.getElementById("YourIdOfCheckBoxHERE");
    checkBoxValue = checkBox.value;
    You can also use the jQuery library by doing this:

    Code:
        $(document).ready(function(){
            if ($('#edit-checkbox-id:checked').val() !== null) {
            // Insert code here.
            }
        });
    Hope this helps,
    Shaun


  •  

    Posting Permissions

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