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

  • SEARCH
  • Home
  • 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 9016107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:54:40+00:00 2026-06-16T03:54:40+00:00

I’m creating a web page that uses PHP and am trying to load an

  • 0

I’m creating a web page that uses PHP and am trying to load an XML file depending on the users selection. I’ve had a look on various websites and forums to see if i’m doing something wrong but even if I try replicating the code it doesn’t seem to work. I’ve come to the conclusion that I need a fresh pair of eyes to notice something that maybe I haven’t. When I choose an item from the dropdown list I want it to load the selected XML file and display the information that is in it but with the code I have so far nothing at all happens. I select an option from the dropdown list and nothing happens. I think it’s a problem with the loading of the XML file because when I changed the code in the loadXML() function to output the option chosen, it worked. I just can’t figure out why it’s not working. Any help would be greatly appreciated.

<html>
<head>
<h1><u>State Information</u></h1>
</head>
<body>
<p><b>Please select an area of the US in the dropdown list below.</b></p>
<p><select name="area" onchange="loadXML(this.value)">

<?php
//set directory and open it
$xmldir = 'XML';
$dir = opendir($xmldir);

//create array and read through files in directory
$xmlfiles = array();
while ($file = readdir($dir))
{
//if the first char is not '.' then add to array
if (substr($file,-1,1) !== ".")
{
    $xmlfiles[] = $file;
} else
{
    //do nothing
}
}

echo '<option value="select">Select</option>';

foreach($xmlfiles as $area){ 
      echo '<option value="'.$area.'">'.$area.'</option>'; 
}
echo '</select>';

//close directory
closedir($dir);
?>

</p>
</body>
</html>

<script>
function loadXML($area) {
if (window.XMLHttpRequest)
{
    xhttp=new XMLHttpRequest();
}
else
{
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",$area,false);
xhttp.send();
xmlDoc = xhttp.responseXML;
x=xmlDoc.getElementsByTagName("name");

for (i=0;i<x.length;i++)
        {
    document.write(x[i].childNodes[0].nodeValue);
    document.write("
       ");
} 
}
</script>
  • 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-06-16T03:54:41+00:00Added an answer on June 16, 2026 at 3:54 am

    Your xml file path isn’t set correctly, try

    echo '<option value="XML/'.$area.'">'.$area.'</option>'; 
    

    Also you have a multiline string which will cause a syntax error, change

        document.write("
       ");
    

    to something like

        document.write("\n");
    

    Also using document.write after the page loads will overwrite the entire page.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm parsing an XML file, the creators of it stuck in a bunch social

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.