Jump to content

AJAX Help while calling


djbuddhi

Recommended Posts

I just want to display some calculated variable in a text box of a form from ajax .how to call the variable

from ajax to display in the text  box

 

my ajax calculation was done ,the problem is that how to call the variable it the text box

 

Help

 

Link to comment
Share on other sites

Hello !!

 

I assume that you have kept the calculate value in the xmlHttp.responseText..

 

Assumption:

 

 

<form>

some code for ajax calculation..............

.....

.....

 

...

 

<input type=text name=txtValue id=txtValue>

</form>

 

if the process is completed you will have the values in "xmlHttp.responseText"

 

you can display the value into textbox using..

 

document.getElementById('txtValue').value = xmlHttp.responseText;

 

Thanks

shang.. :)

Link to comment
Share on other sites

where to put it my code here

 

function ajaxFunction(){

var ajaxRequest;  // The variable that makes Ajax possible!

 

try{

// Opera 8.0+, Firefox, Safari

ajaxRequest = new XMLHttpRequest();

} catch (e){

// Internet Explorer Browsers

try{

ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try{

ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e){

 

alert("Your browser broke..!Pls Try Again ...!");

return false;

}

}

}

// Create a function that will receive data sent from the server

ajaxRequest.onreadystatechange = function(){

if(ajaxRequest.readyState == 4){

var ajaxDisplay = document.getElementById('diveInfo');

ajaxDisplay.innerHTML = ajaxRequest.responseText;

 

 

}

}

 

 

   

 

Link to comment
Share on other sites

yes i am using php and with mysql .what will be the problem

 

 

here is the full code

 

//Browser Support Code

function ajaxFunction(){

var ajaxRequest;  // The variable that makes Ajax possible!

 

try{

// Opera 8.0+, Firefox, Safari

ajaxRequest = new XMLHttpRequest();

} catch (e){

// Internet Explorer Browsers

try{

ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try{

ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e){

 

alert("Your browser broke..!Pls Try Again ...!");

return false;

}

}

}

// Create a function that will receive data sent from the server

ajaxRequest.onreadystatechange = function(){

if(ajaxRequest.readyState == 4){

var ajaxDisplay = document.getElementById('diveInfo');

ajaxDisplay.innerHTML = ajaxRequest.responseText;

document.getElementById('result').value = xmlHttp.responseText;//

 

 

}

}

 

 

   

 

 

 

  var txtsum_inssured= document.getElementById("sumasssured").value;

  var txtsrcctc  = document.getElementById("srcctc").value;

  var txtndc  = document.getElementById("ndc").value;

  var txtradio  = document.getElementById("poloption").value;

 

 

  if(txtsum_inssured ==0)

{ alert("Select the Sum Insured Amount from the List ..!");

document.getElementById("sumasssured").focus();

return false;}

 

 

 

 

else{ // var queryString = "?server_agent_name="+server_argent +"&set_address="+set_address+"&set_ag_telno="+set_telno +"&set_ag_fax_no="+set_faxno +"&set_ag_email_no="+set_email +"&set_upid="+tbl_my_id +"&prev_ag_name="+pre_ag_name +"&prev_ag_add="+pre_adddress +"&prev_ag_telno="+pre_telno +"&prev_ag_faxno="+pre_faxno +"&prev_ag_email="+pre_email_no +"&prev_set_agid="+pre_setagent_id +"&prev_town_id="+pre_townid +"&new_setle_id="+new_setid +"&new_town_id="+new_townid  ;

 

            var queryString = "?sum_insured="+txtsum_inssured +"&srcctc="+txtsrcctc+"&ndcamount="+txtndc +"&poloption="+txtradio;

 

ajaxRequest.open("GET", "script/ajax_get_policy_infor.php" + queryString, true);

ajaxRequest.send(null);

}

}

 

Link to comment
Share on other sites

Is this file ajax_get_policy_infor.php contains any html content??

 

The PHP page you are using in script should contain only PHP code...

Should be like this:

<?php

echo "This page is executed by ajax";

?>

Should not be like this:

<html>

<head>

</head>

<body>

<?php

echo "This page is executed by ajax";

?>

</body>

</html>

 

 

So clear all html entites and echo the value which you are calculating...

 

It will give you result..

 

Link to comment
Share on other sites

thanks guys for the support and it really works .thanks to all the people who support me

 

here my calculation code

 

 

include_once'./../include/connection_db.php';

include_once'./../include/my_para_list.php';

 

$category=$_GET['sum_insured']; 

 

$srcctc_option=$_GET['srcctc'];

$ndc_amount=$_GET['ndcamount'];

//echo "dd".

$pol_type=$_GET['poloption'];

//print"<br>";

 

$tot_premium=0;

$ind_charge=0;

$ndc_charge=0;

$in_plus_fam_tot=0;

$in_plus_fam_parent_tot=0;

$in_plus_parent_tot=0;

$srcctcc_charge=0;

 

 

$result = mysql_query("SELECT * FROM policy_option WHERE pol_op_state='A' AND pol_op_sum_assured=$category");

 

while ($row = mysql_fetch_assoc($result))

  {

  $indvidual = $row['pol_op_individual'];

$ind_p_or_family = $row['pol_op_ind_plus_p_or_family'];

$ind_p_family = $row['pol_op_ind_plus_p_plus_family'];

$ndc = $row['pol_op_natural_death_cover'];

$opsrsctc = $row['pol_op_srcc_tc'];

    }

 

if ($pol_type==1) { $ind_charge=$ind_charge+$indvidual;} else{$ind_charge=0;}

if ($pol_type==2) { $in_plus_fam_tot=$in_plus_fam_tot+$ind_p_or_family;} else{$in_plus_fam_tot=0;}

if ($pol_type==3) { $in_plus_parent_tot=$in_plus_parent_tot+$ind_p_or_family;} else{$in_plus_parent_tot=0;}

 

if ($pol_type==4) { $in_plus_fam_parent_tot=$in_plus_fam_parent_tot+$ind_p_family;} else{$in_plus_fam_parent_tot=0;}

 

 

if ($ndc_amount==1) { $ndc_charge=$ndc_charge+$ndc;} else{$ndc_charge=0;}

if ($srcctc_option==1) { $srcctcc_charge=$srcctcc_charge+$opsrsctc;} else{$srcctcc_charge=0;}

 

 

            $tot_premium=$tot_premium+$ind_charge+$in_plus_fam_tot+$in_plus_parent_tot+$in_plus_fam_parent_tot+$ndc_charge+$srcctcc_charge;

 

 

echo number_format($tot_premium,2 );

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.