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 7531869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:17:19+00:00 2026-05-30T05:17:19+00:00

So i am trying to make a function that searches trough an xml file,

  • 0

So i am trying to make a function that searches trough an xml file, my results are given but the page is refreshed and keeps loading. I figured this was because of a submit but i used return false and i still have the same problem. Can anyone help me?

Below is my code

    <script type="text/javascript">
function loadXMLDoc(XMLname)
{
var xmlDoc;
if (window.XMLHttpRequest)
  {
  xmlDoc=new window.XMLHttpRequest();
  xmlDoc.open("GET",XMLname,false);
  xmlDoc.send("");
  return xmlDoc.responseXML;
  }
else if (ActiveXObject("Microsoft.XMLDOM"))
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load(XMLname);
  return xmlDoc;
  }
alert("Error loading document!");
return null;

}
</script>
</head>
<body>
<form id="oForm" name="oForm" onsubmit="search(); return false">
<input type="text" name="name" id="txt_name" size="30" maxlength="70">
<input type="submit" value="klik" onclick="search()"/>
</form>
<script type="text/javascript">

function search(){
name = document.oForm.name.value.toLowerCase();
xmlDoc=loadXMLDoc("data.xml");
var nodeList = xmlDoc.getElementsByTagName("article");
for (var i = 0; i < nodeList.length; i++) {
    var titleNode = nodeList[i];

    if(titleNode.getElementsByTagName("title")[0].childNodes[0].nodeValue.toLowerCase() == name){
        document.write("<div style='width:450px;'>")
        document.write("<p>"+titleNode.getElementsByTagName("title")[0].childNodes[0].nodeValue+"</p>");
        document.write("<p>"+titleNode.getElementsByTagName("description")[0].childNodes[0].nodeValue+"</p>");
        document.write("<p>"+titleNode.getElementsByTagName("urltext")[0].childNodes[0].nodeValue+"</p>");
        document.write("</div>")
    }
}
}
</script>

I would like to repeat that i do get results i only lose my layout and the page keeps loading. I made this for safari/safari mobile so i would apreciate it if someone could present a solution. I cant use any serversided scripts either since i need to be able to cache this offline so i figure it has to be javascript.

Ty in advance

EDIT

    <input type="text" name="name" id="txt_name" size="30" maxlength="70">
<input type="button" value="klik" onclick="search();"/>

name = GetElementById("txt_name").value.toLowerCase();
  • 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-30T05:17:20+00:00Added an answer on May 30, 2026 at 5:17 am

    Assuming the xml processing code works, do it like this – document.write WIPES the page
    PS: Firefox MAY not work as expected due to linefeeds in the XML:

    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc(XMLname) {
      var xmlDoc;
      if (window.XMLHttpRequest) {
        xmlDoc=new window.XMLHttpRequest();
        xmlDoc.open("GET",XMLname,false);
        xmlDoc.send("");
        return xmlDoc.responseXML;
      }
      else if (ActiveXObject("Microsoft.XMLDOM")) {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.load(XMLname);
        return xmlDoc;
      }
      alert("Error loading document!");
      return null;
    }
    var xmlDoc=loadXMLDoc("data.xml");
    var nodeList = xmlDoc.getElementsByTagName("article");
    function search(theForm) {
      var name = theForm.myname.value.toLowerCase();
      var html = "";
      for (var i = 0; i < nodeList.length; i++) {
        var titleNode = nodeList[i];
        if (titleNode.getElementsByTagName("title")[0].childNodes[0].nodeValue.toLowerCase() == name) {
          html += "<div style='width:450px;'>";
          html += "<p>"+titleNode.getElementsByTagName("title")[0].childNodes[0].nodeValue+"</p>";
          html += "<p>"+titleNode.getElementsByTagName("description")[0].childNodes[0].nodeValue+"</p>";
          html += "<p>"+titleNode.getElementsByTagName("urltext")[0].childNodes[0].nodeValue+"</p>";
          html+= "</div>";
          document.getElementById("result").innerHTML=html
        }
      }
      return false; // cancel the submit
    }
    </script>
    </head>
    <body>
    <form id="oForm" name="oForm" onsubmit="return search(this)">
    <input type="text" name="myname" id="txt_name" size="30" maxlength="70">
    <input type="submit" value="klik"/>
    </form>
    <div id="result"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a function that holds state but is called with foo().
Im trying to make a function that will return an element of type point:
I'm trying to make a function that will take short hand hex color to
I'm trying to make a Javascript function that will take a mathematical expression and
GCC seem to think that I am trying to make a function call in
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to make a notification area that will show alerts. return this.each(function() {
I'm trying to make a function that takes one of many classes that extends
I am trying to make a function that will determine if value in a
I am trying to make this function that extracts text from html for multiple

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.