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 5 of 5

Thread: Checkbox issue

  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkbox issue

    Firstly, hi, my first post in these forums.

    Onto to my problem. I have a set of checkboxes and a button that selects them all. I am able to do this via Javascript.

    Javascript:
    Code:
    function SelectAll2() {
     boxnum = 0;
     for (boxnum=0; boxnum <= 12; boxnum++){
      document.cform.criteria[boxnum].checked = true;
     }
    }
    I also have a button that submits the values of all selected checkboxes to a php form. This I've also achieved.

    Form with button:
    Code:
    <FORM action="http://localhost/mycode.php" name=optionsform METHOD="POST">
    <input type="checkbox" name="criteria[]" value="check1">
    <input type="checkbox" name="criteria[]" value="check2">
    
    <INPUT TYPE=SUBMIT VALUE="SORT" >
    </form>

    The problem I am not able to do both of them with the same script. That is when selecting all boxes using javascript, I have to name the checkboxes as "criteria".
    But for the php to work I have to name them as "criteria[]". I can change this to "critera[]" but then I have to use $_GET but I'd rather use $_POST.

    So any suggestions on how I can work around this? Any help is appreciated, thanks.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    You need to give the checkboxes an id and then target them using that in your javascript instead of the name. The name is important for server side scripts. For client side JS always use an id.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I've managed to do that using 'getElementById' now.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Please would you ask your javascript questions in the html/javascript forums?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wasn't sure if I should put it in Javascript or the PHP forum, since the code pertained to both. I was looking for a solution for either script.


  •  

    Posting Permissions

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