SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using checkboxes

    Hi
    I need to get the id of checkboxes selected from the form, store them in an array and insert the value to the table, after clicking on submit button.

    for($i=1;$i<13;$i++) {
    <input name= 'cat[$i]' id='$i' type='checkbox' onClick=' check_cancelrecur(this)' />
    }

    function check_cancelrecur(test_id)
    {

    //alert(test_id.id);

    var selected_line = new Array();
    var i=0;
    var count=0;

    count=test_id.id;

    for(i=0;i<= count;i++)
    {
    selected_line[i]=count; // don't know whether it's correct way or not

    }

    }


    I tried by using the code as shown above but i m little confused about using javascript arrays in php


    Any suggestions

    Thanks
    sampada

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't want to use a number as the id property of an element. Prefix it with a letter or short string:

    PHP Code:
    <?for ($i=0;$i 13$i++): ?>
    <input id="checkbox_<?php echo $i?>" />
    <?endfor; ?>
    The form element has an elements property, which is a JavaScript array containing all the child elements (e.g., input elements) of the form.

    Code:
    for (var i=0; i < document.getElementById('someForm').elements.length;i++)
     alert(document.getElementById('someForm').elements[i].getAttribute('id');

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    thanks for the reply.
    I got it working.
    function CheckLikes() {

    boxes = document.f1.cancel_recur.length; //get the total number of checkboxes
    txt="";
    for(var i=0;i<boxes;i++)
    {
    if(document.f1.cancel_recur[i].checked)
    {

    txt = txt + document.f1.cancel_recur[i].value + ";" +"";
    }
    }

    window.open("http://localhost/xxx/xxx/main.php?txt="+txt);

    }

    <form name="f1" method="post" action="" onSubmit="return CheckLikes()" enctype = text/plain>


    But now I want to retreive the value contained in "txt". window.open is not working. It redirects to that page but I get error message as

    Page requested not found

    Any suggestion
    Thanks


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
  •