...

View Full Version : browser not detecting an element by document.getElementById



bhakti_thakkar
06-10-2008, 07:27 AM
hi all,
i am using AJAX to retrieve some data from a textbox. it appears on the called paged page and its 100% sure as it appears on the page , but when i try to alert the object it returns object error. when i do :
alert(xmlHttpcinf_IMPO.responseText);

i can see the <input type ='text' name='destinationcountry' value='somevalue'>

but when i try to do : alert(document.getElementById("destinationcountry").value);
it returns null. i read somewhere that when the page is rendered to the client, the actual ID is changed to somthing else. how can i get my object?? :eek:

thanks in advance.

liorean
06-10-2008, 07:39 AM
getElementById works on IDs, not on names, so you should not expect that to work at all.

bhakti_thakkar
06-10-2008, 08:32 AM
hi liorean,
i am extremely sorry that i missed to mention the id in the thread, below is the code:
<input type ='text' name='destinationcountry' id='destinationcountry' value='somevalue'>
it is there. but still the browser (IE 6) doent seem to get it. hope i get some help in this as i have done this in multiple pages and it does work..

abduraooft
06-10-2008, 09:04 AM
Could you post your complete code or a link to your page?

bhakti_thakkar
06-10-2008, 09:21 AM
below is my code:
main page is TransactionCertificate.php and in this page i select from autocomplete AJAX control some importer and the Importer_ID is passed to getImportersAddress.php so that can display the address of the selected importer and i am loading a textbox in getImportersAddress.php which holds the importer country and want that value in TransactionCertificate.php which i am not able to get.


TransactionCertificate.php :




function ChangeContactInfoImporter(ROID , SpanObj ) {
frm = document.TCMainForm;
ReadOnly_ID = ROID.value;
xmlHttpcinf_IMPO = GetXmlHttpObject()
if (xmlHttpcinf_IMPO ==null) {
alert ("Browser does not support HTTP Request")
return
}
url="getImportersAddress.php?Relation_IDImp="+ReadOnly_ID
url=url+"&sid="+Math.random()
// alert(url);
xmlHttpcinf_IMPO.onreadystatechange=function(){ stateChangecinfImp(SpanObj); }
xmlHttpcinf_IMPO.open("GET",url,true)
xmlHttpcinf_IMPO.send(null)
}


function stateChangecinfImp(param) {
if (xmlHttpcinf_IMPO.readyState==4 || xmlHttpcinf_IMPO.readyState=="complete") {
// alert(xmlHttpcinf_IMPO.responseText);
// alert(document.getElementById("COD").value);// contryofdestint=document.getElementById("COD").value;
// alert(contryofdestint);
// document.getElementById('Box8').innerHTML = contryofdestint;
document.getElementById(param).innerHTML = xmlHttpcinf_IMPO.responseText;
}
}





code in getImporterAddress.php




<?
require_once ('include.php');

if($Relation_IDImp!="") {
$data=GetMultipleData("Name_VC , Address_VC , PostalCode_VC , City_VC , State_VC , Country_ID " , "Relation_T " , " Relation_ID ='".$Relation_IDImp."'" , $db);

if($data[0]['Name_VC']!='') {
print("<br>");
print_r($data[0]['Name_VC']);

}
if($data[0]['Address_VC']!='') {
print("<br>");
print_r($data[0]['Address_VC']);
}

if($data[0]['PostalCode_VC']!='') {
print("<br>");
print_r($data[0]['PostalCode_VC']);
}

if($data[0]['City_VC']!='') {
print("<br>");
print_r($data[0]['City_VC']);
}

if($data[0]['State_VC']!='') {
print("<br>");
print_r($data[0]['State_VC']);
}

if($data[0]['Country_ID']!='') {
print("<br>");
$Country_ID =$data[0]['Country_ID'];
print(GetData("Country_VC", "Country_T", " Country_ID = '$Country_ID'" ,$db));
print("<br><BR>");

$contryofdetin=GetData("Country_VC", "Country_T", " Country_ID = '$Country_ID'" ,$db);
print "<input type='text' name='COD' id='COD' value='".$contryofdetin."'>"; print "<b>8. Country of destination: ".$contryofdetin."</b>";
}
}

?>
i am unable to get the COD object on TransactionCertificate.php.
hope i get some help. :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum