0

i am new in php so may be my problem could be so easy for u but i m not solve.
anyone out there please help me.

actually i am creating checkboxes inside the while loop with different id.
and a user can check more than one checkbox and when click on the button the value of the checkbox should be shown in the div as the result.

the code goes like this

the code which create checkbox with different id is

  <?php 

             $ret = mysql_query("SELECT * FROM workshopservicerate  WHERE SID = '".$row['SID']."' order by SID DESC");
            $cnt=1;
            while($row=mysql_fetch_array($ret))
            {   
            ?>
              <tr >                    
              <td height="33" valign="middle"><div align="center"><span class="leftlink"><?php echo $cnt; ?></span></div></td>
              <td style="width:20px;">
<input type="checkbox" id="chk<?php echo ucfirst($row['pid']); ?>"  /></td>
                <td class="leftlink"><?php echo ucfirst($row['Title']);?> <?php echo ucfirst($row['lastname']);?></td>
                <td valign="top" class="leftlink"><?php echo $row['Rate'];?></td>
               </tr>
                    <?  $cnt=$cnt+1;
               } ?>

the button on which the funciton is called on onclick event is

<input type="button" onclick="calculate('chk<?php echo ucfirst($row['pid']); ?>',<?php echo ucfirst($row['Rate']); ?>);"/>

the function which added the values is like this

<script type="text/javascript">
 var calculatedValue=0;
function calculate(chkid,chkvalue)
{
 if(document.getElementById(chkid).checked==true)
 { 
    calculatedValue=calculatedValue+chkvalue;
 }
 else
 {
        calculatedValue=calculatedValue-chkvalue;
 }
 document.getElementById('result').innerHTML=calculatedValue;
 alert(calculatedValue);
}
</script>

the div on which the result is to shown is

<div id="result"></div>

on clicking the button there is no answer
so if anybody knows what the problem is please help me

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pssubash
0

on my understanding,
the problem is in the below code.

<input type="button" onclick="calculate('chk<?php echo ucfirst($row['pid']); ?>',<?php echo ucfirst($row['Rate']); ?>);"/>

better to do one thing,please alert the chkid,chkvalue values then you better understanding what are the value are got inside the function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.