Jump to content

getting data from checkbox input in html forms?


ShadowFire

Recommended Posts

I've been poking around online for about a day now trying to find a good way to do the following:

 

I have an "order" I'm reading in from a MySQL database (not completely relevant, but just fyi). And, for this order there are a number of "parts" (automotive parts) that have been ordered. For each part there is data pertaining to the quantity of parts that have been ordered and the number of parts that have been allocated (based on our inventory) and then a third column that has the number of parts still in that order that are still to be allocated at a future date.

 

Basically, I'm displaying this data in a form with each row having a checkbox to the far left. What I want to do is allow the user to check any number of check boxes. If a check box is checked the form should submit all of the input text boxes for that row (the user can update the quantities) that I talked about in the second paragraph for that "part" (each part is displayed in a row and has a checkbox).

 

Unfortunately, most of the examples I found for checkboxes in a form submit a specific value (like a number of a letter). I need the form to submit the values that are in the textboxes. So basically, I'm thinking I need the page to update a PHP object whenever the value of a textbox is changed and then when the user clicks a button it will send the php object for each checked row through GET or POST. But, how would I get it to onchange update a PHP object (the PHP object would need to be a 2-D array where the first index allows you to select the part and the second index allows you to select which quantity you will change). I'm thinking I would need to call a script from the onchange like: onchange="somePHPfunction(partNumberIndex, whichQuantityI'mChanging, currentValueOfThatQuantity)" but of course that would require me to embed some php inside the onchange call since the partNumberIndex and whichQuantity are PHP variables..

 

Any ideas on how to do this sort of thing?

Or any ideas on how to do this differently?

I'm trying to avoid javascript because it would place a javascript constraint on the users.

But, maybe there's no other way to do this sort of thing?

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

Do you want to update the data which is on your form with these checkboxes. if u checked all check box than are you want that all checked boxes data are display in textboxes where you able to modify the all data and aain insert into the database.

 

if u need like that than attache your pages here on which u want to change.

Link to comment
Share on other sites

I want the data to update in the form (in the input boxes if the checkbox is checked). I also want any changes to be updated in the database (but I know how to do that). I just need to know how to get the data for a whole row to send if the checkbox to the left of that row is checked when the "Apply Changes" button is clicked. Here's what I have right now:

<?php
for($i=0; $order = mysql_fetch_array($orderResults);$i++ )
            {
            ?>
                <table border="1" bgcolor="white">
                    <thead>
                        <tr>
                            <th>Dealer ID</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php echo $order["DealerID"];?></td>
                        </tr>
                    </tbody>
                </table>

         
            <table title="Pending Orders" width="90%" align="center">
<!--            <thead>
                <tr><th colspan="2" align="center">Dealer ID</th><th align="center"><?php echo $order["DealerID"]; ?></th></tr>
            <tr  bgcolor="#CCCCCC">-->
            <th></th>
            <th>Part No.</th>
            <th>Order Quantity</th>
            <th>Allocated Quantity</th>
            <th>Pending Quantity</th>
            <th>Order Type</th>
            </tr>
            </thead>

        <form name="updateQty" action="PendingOrder.php" method="GET">
        <?php
//. htmlspecialchars(serialize($partArray[$k]), ENT_QUOTES) . 
                $partDetailsResults = mysql_query("SELECT * FROM pendingordersdetails WHERE idOrderNo = '$orderID';");
                for($j = 0; $part = mysql_fetch_array($partDetailsResults); $j++)
                {
                    $k = $i + $j;
                    $partArray[$k]["Oqty"] = $part["Oqty"];
                    $partArray[$k]["Aqty"] = $part["Aqty"];
                    $partArray[$k]["Pqty"] = $part["Pqty"];
                    if($part["PartStatus"] == "Regular")
                    {
                        ?><tr id="reg"><?php
                    }
                    else if($part["PartStatus"] == "Excess")
                    {
                        ?><tr id="exc"><?php
                    }
                    else //$part["PartStatus"] == "Abnormal"
                    {
                        ?><tr id="abn"><?php
                    }
                    echo "<td><input type=\"checkbox\" name=\"applyChanges[]\" value=\"" . htmlspecialchars(serialize($partArray[$k]), ENT_QUOTES) . "\"> </td>
                    <td>" . $part["PartNumber"] . "</td>";?>
                    <td><input type="text" name="Oqty" onchange="" value="<?php echo $part["Oqty"]; ?>" /></td>
                    <td><input type="text" name="Aqty" value="<?php echo $part["Aqty"]; ?>" /></td>
                    <td><input type="text" name="Pqty" value="<?php echo $part["Pqty"]; ?>" /></td>
                    <?php
                    if($part["PartStatus"] == "Regular")
                        echo "";
                    else if ($part["PartStatus"] == "Excess")
                        echo "";
                    else
                        echo "";
                    if($part["PartStatus"] == "Regular")
                    {
                        ?>
                        <td>
                        <select>
                        <option id="regular" value="Regular">Regular</option>
                        <option id="excess" value="Excess">Excess</option>
                        <option id="abnormal" value="Abnormal">Abnormal</option>
                        </select>
                        </td>
                        </tr>
                        <?php
                    }
                    else if ($part["PartStatus"] == "Excess")
                    {
                    ?>
                        <td>
                        <select>
                        <option id="regular" value="Regular">Regular</option>
                        <option id="excess" selected ="selected" value="Excess">Excess</option></font>
                        <option id="abnormal" value="Abnormal">Abnormal</option>
                        </select>
                        </td>
                        </tr>
                        <?php
                    }
                    else //$part["Otype"] == "Abnormal"
                    {
                        ?>
                        <td>
                        <select>
                        <option id="Regular">Regular</option>
                        <option id="Excess">Excess</option>
                        <option selected ="selected" id="Abnormal">Abnormal</option>
                        </select>
                        </td>
                        </tr>
                        <?php
                    }
                }
            }
            
            ?>
                    <tr><td colspan="5"></td>
                        <td  align="right"><?php 
                        echo "<input type=\"hidden\" name=\"OrderID\" value=\"$orderID\">";
                        ?>
                        <input type="submit" name="updateQty" value="Apply Changes" />
                        </td>
                    </tr>
            </tbody>
            </table>

 

MOD EDIT:

 . . . 

BBCode tags added.

Link to comment
Share on other sites

Update:

I figured out how to do this. I'm not sure if it's the absolute cleanest solution, but essentially I was unable to get the form to send only the rows which were checked on submit. But, in addition to all of the form data being sent the value field for any checked row will send. In the value field I serialized a PHP variable and then unserialize it on the other end (when the page refreshes). Then, for any indexes that were stored in the data for the rows I sent, I update their entries in the table. Since, the table data is now current (post-updates), I can safely read the values from the database to display any updated data in the form.

 

I think the cleanest solution would be one in which the input boxes of only rows which have been checked when apply changes is clicked, are sent (rather than needing to check each row against the values of the PHP object I serialized). But, for now this should do.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.