hello all, This is the code which adds the values together. function amtTot(){ //fee_tot1 //alert(document.getElementById("fee_tot1").value); var tot_amt=parseFloat(document.getElementById("fee_tot1").value)+parseFloat(document.getElementById("fee_tot2").value)+parseFloat(document.getElementById("fee_tot3").value)+parseFloat(document.getElementById("fee_tot4").value)+parseFloat(document.getElementById("fee_tot7").value)+parseFloat(document.getElementById("fee_tot8").value); //alert(tot_amt); var result = num.toFixed(2); document.getElementById("tot_amt").value=tot_amt; addValueText(); //tot_amt } <input name="tot_amt" type="text" id="tot_amt" value="" size="10" onClick="amtTot();" /> PHP: I want to apply discount on "tot_amt" according to customer_discount field. if customer_discount is "10", i want the "tot_amt" to be "(tot_amt x customer_discount / 100) + tot_amt". How can i do this here? <? if (isset($_POST['get_customer_details'])) { ?> <td><?=$customer_discount;?></td> <td><input name="tot_amt" type="text" id="tot_amt" value="" size="10" onClick="amtTot();" /></td> <? } ?> PHP:
OK, I am not sure what you want to do exactly, but you need to know that javascript and php are different. Javascript executes in the brower, while php execute on the server. But if you still trying to mix the two, probably best is var tot_amt=parseFloat([B][U]<?php echo $customer_discount;?> + [/U][/B]document.getElementById("fee_tot1").value)+parseFloat(document.getElementById("fee_tot2").value)+parseFloat(document.getElementById("fee_tot3").value)+parseFloat(document.getElementById("fee_tot4").value)+parseFloat(document.getElementById("fee_tot7").value)+parseFloat(document.getElementById("fee_tot8").value); Code (markup): Something link that?
Thank you very much you made me think another way and it worked. i did this on the javascript <? if (isset($_POST['get_customer_details'])) { ?> function amtTot(){ //fee_tot1 //alert(document.getElementById("fee_tot1").value); var tot_amt=parseFloat(document.getElementById("fee_tot1").value)+parseFloat(document.getElementById("fee_tot2").value)+parseFloat(document.getElementById("fee_tot3").value)+parseFloat(document.getElementById("fee_tot4").value)+parseFloat(document.getElementById("fee_tot7").value)+parseFloat(document.getElementById("fee_tot8").value); //alert(tot_amt); var result = num.toFixed(2); document.getElementById("tot_amt").value=tot_amt - (tot_amt *<?=$customer_discount;?>/100); addValueText(); //tot_amt } <? }else{ ?> function amtTot(){ //fee_tot1 //alert(document.getElementById("fee_tot1").value); var tot_amt=parseFloat(document.getElementById("fee_tot1").value)+parseFloat(document.getElementById("fee_tot2").value)+parseFloat(document.getElementById("fee_tot3").value)+parseFloat(document.getElementById("fee_tot4").value)+parseFloat(document.getElementById("fee_tot7").value)+parseFloat(document.getElementById("fee_tot8").value); //alert(tot_amt); var result = num.toFixed(2); document.getElementById("tot_amt").value=tot_amt; addValueText(); //tot_amt } <? } ?> PHP:
No problem glad I could help. You could probably condense even more. I think you syntax is wrong equal sign on the wrong side and I dont know what the * is for. I am an expert on javascript. But you need to echo the varable. Here: Should work. They way you dont even need that second function. document.getElementById("tot_amt").value=tot_amt <? if($customer_discount > 0){ ?> - (tot_amt *<? echo $customer_discount;?>/100) <? } ?>;
i have got no idea on javascript. it just worked by chance i think. i changed document.getElementById("tot_amt").value=tot_amt; PHP: into document.getElementById("tot_amt").value=tot_amt - (tot_amt *<?=$customer_discount;?>/100); PHP: