Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 309937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:47:15+00:00 2026-05-12T07:47:15+00:00

I’m having an issue with getElementsByTagName in IE (7 and 8). I have an

  • 0

I’m having an issue with getElementsByTagName in IE (7 and 8).

I have an address lookup that returns each suggested address (as a string of XML) into a PHP session variable, which is then accessed using an AJAX function that returns the requested session variable.

Each session variable is set in step 1 of the ajax address lookup (I have tried with without the character encoding and with utf-8):

$_SESSION['addrHint_' . $k1] = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$_SESSION['addrHint_' . $k1] .= '<Address>';
$_SESSION['addrHint_' . $k1] .= '<Postcode>' . $v1->Postcode . ' </Postcode>';
$_SESSION['addrHint_' . $k1] .= '<Line1>' . $v1->Line1 . ' </Line1>';
$_SESSION['addrHint_' . $k1] .= '<Line2>' . $v1->Line2 . ' </Line2>';
$_SESSION['addrHint_' . $k1] .= '<Line3>' . $v1->Line3 . ' </Line3>';
$_SESSION['addrHint_' . $k1] .= '</Address>';

And then retrieved in step 2:

header('Content-Type: text/xml');
print_r( $_SESSION['addrHint_'.$_REQUEST['addr']] );

In the AJAX js, when the state is ready, it performs amongst other similar lines of code, this:

var xmlDoc = xmlHttp.responseXML;
var xmlRoot = xmlDoc.documentElement;
var postcode = xmlRoot.getElementsByTagName("Postcode")[0].childNodes[0].nodeValue;
document.forms[0]["address"+addr+"_Postcode"].value = postcode.substring(0, postcode.length-1);

(It does a similar thing for each line of the address.) The length-1 snippet is in there because I had to append a space to each element to stop an issue I was having when an element was null.

It works fine in Firefox, but not at all in IE. I have since been Googling and found a number of results among the first 5 pages but no solutions. I’d be most grateful if anyone could shed some light on this.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:47:16+00:00Added an answer on May 12, 2026 at 7:47 am

    Instead of modifying your return values, maybe you should implement some error checking around the code that fetches your node values.

    If you do a ton of chaining you can’t check for nulls.
    Instead of chaining like this:

    xmlRoot.getElementsByTagName("Postcode")[0].childNodes[0].nodeValue
    

    Why not add some error checking before hand?
    Something like:

    var postCodes = xmlRoot.getElementsByTagName("Postcode");
    if( postCodes && postCodes[0] && postCodes[0].childNodes[0] ) {
        document.forms[0]["address"+addr+"_Postcode"].value = postCodes[0].childNodes[0].childNodes[0].nodeValue;
    }
    

    That way you’ll only attempt the assignment if there’s no data there. Getting a blank input value where you expect it.

    Now, all that chaining and if statement can get tiresome, so you can wrap that in a function if you like.

    Feel free to check a working example here: http://jsbin.com/ahidu

    Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.