Page 1 of 1

passing javascript variable value to php without page refres

Posted: Fri Feb 03, 2012 11:16 pm
by lina531
<script type="text/javascript">
function CalculateTotal(){
var p=document.percent.govt_share_capital.value;
var k=document.percent.total_paid.value;
var total=(p/k);
var gtotal=total*100;
//var lll=<?php //echo $gtotal; ?>;
//alert(lll);
}
</script>


<form id="percent" name="percent">
<table>
<tr>
<td>Government share capital out of total paid up share capital</td>
<td><input type="text" name="govt_share_capital" id="govt_share_capital" /></td>
<td>Total Paid up share capital</td>
<td><input type="text" name="total_paid" id="total_paid" /></td>
<td>Percentage of Government share capital to total paid up share capital</td>
<td>
<input type="text" name="gtotal" id="gtotal" value="<?php echo $lll; ?>" onclick="javascript:CalculateTotal();"/>
</td>
</tr>
<?php $total = "<script language=javascript>document.write(gtotal);</script>";
echo $total; ?>
</table>
</form>

Hi,

can anyone please help me for solve this query. I want the function should take input from the 2 fields i.e.govt_share_capital &total_paid and show the percentage in the "gtotal" field on click without page refresh that too in the same page without submitting the form.

thnks.... please help me!!!

Re: passing javascript variable value to php without page re

Posted: Sat Feb 04, 2012 4:25 am
by Gopesh
Hi,u need not pass javascript variable to php.
Try this

Code: Select all

var gtotal=total*100;
document.getElementById("gtotal").value=gtotal;
After this cahnge the Html code as

Code: Select all

<input type="text" name="total_paid" id="total_paid" onchange="CalculateTotal()" />

It is not the complete solution,but hope that you got the idea of solving the problem.

Solved: passing javascript variable value to php without pag

Posted: Sun Feb 05, 2012 10:04 pm
by lina531
thanks

ya this code helps me. it works correctly........................

Re: passing javascript variable value to php without page re

Posted: Sun Feb 05, 2012 11:33 pm
by Gopesh
ok..If your problem is solved,pls change the heading as solved..Good Luck