Passing javascript variable value to php without page refresh

<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!!!

Not possible, with PHP.

<script type=“text/javascript”>
function CalculateTotal(){
var p=(document.percent.govt_share_capital.value);
var k=(document.percent.total_paid.value);
var pertotal=(p/k);
var gtotal=pertotal100;
document.percent.total.value=gtotal;
var a=(document.percent.one.value);
var b=(document.percent.two.value);
var ptotal=(a/b);
var gtotal1=ptotal
100;
document.percent.total1.value=gtotal1;
var c=(document.percent.three.value);
var d=(document.percent.four.value);
var ptotal1=(c/d);
var gtotal2=ptotal1*100;
document.percent.total2.value=gtotal2;
}
</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=“total” id=“total” onclick=“javascript:CalculateTotal();”/>
</td>
</tr>
<tr>
<td>1st</td>
<td><input type=“text” name=“one” id=“one” /></td>
<td>2nd</td>
<td><input type=“text” name=“two” id=“two” /></td>
<td>Percentage</td>
<td>
<input type=“text” name=“total1” id=“total1” onclick=“javascript:CalculateTotal();”/>
</td>
</tr>
<tr>
<td>3rd</td>
<td><input type=“text” name=“three” id=“three” /></td>
<td>4th</td>
<td><input type=“text” name=“four” id=“four” /></td>
<td>Percentage</td>
<td>
<input type=“text” name=“total2” id=“total2” onclick=“javascript:CalculateTotal();”/>
</td>
</tr>
</table>
</form>

Yes, it is possible.
Without page refresh and multiple times in a form. The corretced code are given in above try it.
Thanks

By using Javascipt, not PHP. You are in the PHP forum.

You can communicate between javascript and php by using AJAX.
Otherwise it is not possible.
Javascript is client side (executed on the users computer)
PHP is server side (executed on your own server)

Ajax recommendation again however ajax is basically javascript not PHP. You need no special PHP code to work with ajax, the ajax call just calls the .php file like a normal http request.