SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Melbourne
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing checkbox values to another form as an array

    Hi all,
    I'm wanting to know how to pass a value of a checkbox upon onClick to another form so i can send it as a hidden field.
    At the moment i have the following page called add_special.php
    Code:
    <script Language="JavaScript">
    <!--
    
    // not sure what to add here
    
    //-->
    </script>
    
    <FORM action="<? $PHP_SELF ?>" method="post" name="parentform" id="parentform" enctype="multipart/form-data">
     <table width="100%"  border="0" cellpadding="0" cellspacing="5" bgcolor="#F0F0F0">
            <tr>
              <td width="200"><input name="text1" type="text" id="text1" value="" size="40"></td>
              <td width="70%">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" colspan="2"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="1">
    <?
    include ("include/dbconnect.php");
    
    ?>
    <IFRAME SRC="include/specials_list.php" TITLE="Specials" WIDTH=97% HEIGHT=200 id="pframe" name="pframe" >
    </IFRAME>
                
    </td>
                  
                </tr>
              </table></td>
            </tr>
     </table>
    </FORM>
    The specials_list.php which runs via the IFRAME looks like:
    PHP Code:
    <form name="baby" method="post" action="">
    <?
    include ("dbconnect.php");
    $sql "select * from cart_products"
    $sql_result mysql_query($sql) or die ("Could not select data"); 
    while (
    $row mysql_fetch_array($sql_result)){
    $prod_id $row['prod_id'];
    $prod_name stripslashes($row['prod_name']);
    ?> 
    <div><input name="special_prod_id" type="checkbox" value="<? echo $prod_id?>" onClick="parent.document.parentform.text1.value='<? echo $prod_id?>';"><? echo $prod_name?></div>
    <?
    }
    ?>
    </form>
    At the moment (for test purposes) i am displaying the output to the text1 input field of the add_special.php page which it does however i want it to put the values into an array then display them and also if the checkbox is unchecked that the value be removed from the array and the updated array displayed?

    I hope that makes sense. If not please ask questions and i'll try and answer them best i can.

    Cheers

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •