Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    browser not detecting an element by document.getElementById

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

    thanks in advance.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    getElementById works on IDs, not on names, so you should not expect that to work at all.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post
    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..

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Could you post your complete code or a link to your page?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post
    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 :

    Code:
    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


    PHP Code:
    <?
    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:
    Last edited by bhakti_thakkar; 06-10-2008 at 09:24 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •