I'm new to PHP, can some one help that how do I do following. Your help will be grate... I'm sutck for this for past 3 days.
Scanario :
- I'm displaying the module list to the user using HTML Table, following the code :
<?
print("<table name=$tblName width=100% cellspacing=\"2\" cellpadding=\"2\">");
print("<tr bgcolor=\"#FFDCB9\"> <td colspan=4 align=center > <b>Semester $semVal </b> (Select total modular weight between $ruleMin and $ruleMax.) </td> </tr>");
print("<tr bgcolor=\"#FFDCB9\"> <th colspan=4 align=center > </th> </tr>") ;
print("<tr bgcolor=\"#FFCC99\" border=1> ");
print("<th> Module Code </th>");
print("<th> Module Name </th>");
print("<th> Weight </th>");
print("<th> Select </th>");
print("</tr>");
for ($i=0; $i < $num_row ; $i++){
$row = mysql_fetch_array($result);
printf("<tr>");
print("<td width=17%> $row[mod_id] </td>");
print("<td> $row[title] </td>");
print("<td width=8%> $row[mod_wt] </td>");
$chk_name = $chbName. $i;
$mod_id = $row[mod_id];
print("<td width=8%> <input type=checkbox name=$chk_name onClick=\"fn_chk(this,$row[mod_wt],$semVal);\"> </td>");
printf("</tr>");
} // end of for loop
print("</table>");
- I'm calling the JavaScript function fn_chk() when the checkbox is selected. Where I'm increasing or decreasing the total module weight for the semester and total module weight for year, depending upon the checkbox is checked / unchecked. Following is the code for the same.
function fn_chk(chkname, mod_wt, semVal){
var js_txt_sem1_tot = Number(document.frm_bsc_cs.txtSem1Tot.value);
var js_txt_tot_crd = Number(document.frm_bsc_cs.yearTot.value);
var js_txt_sem2_tot = Number(document.frm_bsc_cs.txtSem2Tot.value);
if (semVal == 1){
if (chkname.checked){
js_txt_sem1_tot += mod_wt;
js_txt_tot_crd += mod_wt;
}
else{
js_txt_sem1_tot -= mod_wt;
js_txt_tot_crd -= mod_wt;}
document.frm_bsc_cs.txtSem1Tot.value = js_txt_sem1_tot;
}
if (semVal == 2){
if (chkname.checked){
js_txt_sem2_tot += mod_wt;
js_txt_tot_crd += mod_wt;}
else{
js_txt_sem2_tot -= mod_wt;
js_txt_tot_crd -= mod_wt;}
document.frm_bsc_cs.txtSem2Tot.value = js_txt_sem2_tot; }
document.frm_bsc_cs.yearTot.value = js_txt_tot_crd;
} // end of function fn_chk()
I have to have the list of selected modules for the both the semester. And I need to add those modules into the DB, when the submit button is pressed.
My problem is,
1. How do I store those selected modules temporarily until user will click on submit. (shall I store in JavaScript Array?)
- If I have store them temporarily in JavaScript Array, how do I access those from PHP code to insert into the DB?
Please ask me, if I haven't described properly.