klpang Posted February 17, 2009 Share Posted February 17, 2009 I have some dynamic checkboxes and corresponding textboxes. <?php $sqlvas = "SELECT * FROM vas ORDER BY vasname"; $resultvas = mysql_query($sqlvas); $rowvas = mysql_fetch_array($resultvas); ?> <TR> <TD><?php IF ($rowvas) { DO { ?> <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="txtDate[]" MAXLENGTH="10" SIZE="15"><BR> <?php } while ($rowvas = mysql_fetch_array($resultvas)); }?> When a user ticks a checkbox and enters data into the corresponding textbox and submits, the value of the checkbox and textbox should be inserted into the database. I can insert the checkbox values perfectly, but the textbox values have issues. How to match the textbox and check has been checked and insert into database after post it to next page? Does it will involve javascript to handle it? Please advise. Quote Link to comment https://forums.phpfreaks.com/topic/145548-solved-php-insert-checkbox-val-textbox-val/ Share on other sites More sharing options...
sasa Posted February 17, 2009 Share Posted February 17, 2009 change form patr to <?php $sqlvas = "SELECT * FROM vas ORDER BY vasname"; $resultvas = mysql_query($sqlvas); $rowvas = mysql_fetch_array($resultvas); ?> <TR> <TD><?php IF ($rowvas) { DO { ?> <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="txtDate[<?php echo $rowvas["vasID"]; ?>]" MAXLENGTH="10" SIZE="15"><BR> <?php } while ($rowvas = mysql_fetch_array($resultvas)); }?> and on submit page try foreach($_POST['vas'] as $id){ echo $id, ' --> ', $_POST['txtDate'][$id]; } Quote Link to comment https://forums.phpfreaks.com/topic/145548-solved-php-insert-checkbox-val-textbox-val/#findComment-764132 Share on other sites More sharing options...
klpang Posted February 18, 2009 Author Share Posted February 18, 2009 Thanks a lot. it solve partial of the problem. How should i to validate the txtdate by validate with javascript after click the submit button. Please advise. Quote Link to comment https://forums.phpfreaks.com/topic/145548-solved-php-insert-checkbox-val-textbox-val/#findComment-764905 Share on other sites More sharing options...
klpang Posted February 18, 2009 Author Share Posted February 18, 2009 Dear Sasa, Please ignore previous reply. i already find a way to validate the txtdate and successful insert into tables individually. if need to edit, how do i know which package is has been checked by customer and the date text box and remark textarea will also will display information. $sql2 = "SELECT group_concat(vas) as vas from woservice WHERE workorderID = '$workorderID'"; print $sql2; $result2 = mysql_query($sql2) or die (mysql_error()); $row2 = mysql_fetch_array($result2); $package=explode(",", $row2["vas"]); <?php $sqlvas = "SELECT * FROM vas ORDER BY vasname"; $resultvas = mysql_query($sqlvas); $rowvas = mysql_fetch_array($resultvas); ?> <TR> <TD><?php IF ($rowvas) { DO { ?> <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="vasDate[<?php echo $rowvas["vasID"]; ?>]" MAXLENGTH="10" SIZE="15" ONBLUR=javascript:isDate(this.value);> <FONT CLASS="normalText">(dd-mm-yyyy)</FONT><BR><FONT CLASS="UserSort">Remark</FONT> <TEXTAREA COLS="30" ROWS="3" NAME="vasremark[<?php echo $rowvas["vasID"]; ?>]"></TEXTAREA><BR> <?php } while ($rowvas = mysql_fetch_array($resultvas)); }?> </TD> </TR> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/145548-solved-php-insert-checkbox-val-textbox-val/#findComment-765115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.