calculate.php <form method="post" name="frm_deptcal" id="frm_deptcal" action="javascript:add(document.getElementById('frm_deptcal'));" > <span style="font-weight:bold;">Enter your total unsecured* debt </span> <input type="text" name="txt_principal" id="txt_principal" / > <input type="submit" name="button" value="Calculate" style="background: none repeat scroll 0% 0% rgb(51, 136, 180); color: white; border: 5px solid rgb(120, 176, 205); cursor: pointer;"> </form> in ajax_cal.js i have add() in which XMLHttpRequestObject is created and string is send code : <pre> var str1= "txt_principal=" + document.getElementById("txt_principal").value; XMLHttpRequestObject.onreadystatechange = show; XMLHttpRequestObject.open('POST', 'value.php', true); XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); XMLHttpRequestObject.send(str1);
In value.php i have done calculation: $principal=$_POST['txt_principal']; $x=0.3; $consumer_mon_pay=60; $mp_consumer_ans=($principal * $x)/$consumer_mon_pay; $mp_consumer=round($mp_consumer_ans,3) ; echo $mp_repay."[BRK]".$mp_conloan."[BRK]".$mp_credit."[BRK]".$mp_consumer; and in ajax_cal.js i have got the response as html and showed in textbox function show() { if (XMLHttpRequestObject.readyState == 4) { if (XMLHttpRequestObject.status == 200) { data = XMLHttpRequestObject.responseText.split("[BRK]"); document.getElementById('txt_mp_repay').innerHTML = data[0]; document.getElementById('txt_mp_conloan').innerHTML = data[1]; document.getElementById('txt_mp_credit').innerHTML = data[2]; document.getElementById('txt_mp_consumer').innerHTML = data[3]; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)