JavaScript - Search Xml Document
i want to search the index.xml file throu diff input like combo box and input text shown in the search.html file and output the result in a tale.
search.html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Search</title> <script type="text/javascript" src="search%20xml/search%20xml%20with%20mouseover%20table/searchindex.js"></script> </head><body> <form name="frmMain" id="frmMain" action=""> <b>Search Document: <br> <br> <br> Choose Book <select name="Select1"> <option selected="">--All--</option> <option>b1</option> <option>b2</option> </select><br> <br> Choose year <select name="Select2"> <option selected="">--All--</option> <option>1979</option> <option>1980</option> </select><br> </b><br> <strong>Doc_No</strong> <input name="Text1" type="text"><br> <br> <strong>Subject</strong> <input name="Text2" type="text" style="width: 356px"><br> <br> <input value="Submit" onclick="searchIndex(); return false;" type="submit"> </form> </body> </html> index.xml Code: <?xml version="1.0" ?> <books> <book name="b1"> <year date="1979"> <Document Doc_No="17" Subject="s1" path="ta3amime\1979\17_1979.tif">17_1979_s1.tif</Document> <Document Doc_No="18" Subject="s2" path="ta3amime\1979\18_1979.tif">18_1979_s2.tif</Document> </year> <year date="1980"> <Document Doc_No="19" Subject="s3" path="ta3amime\1980\19_1980.tif">19_1980_s3.tif</Document> <Document Doc_No="6" Subject="s4" path="ta3amime\1980\6_1980.tif">6_1980_s4.tif</Document> <Document Doc_No="1" Subject="s5" path="ta3amime\1980\1_1980.tif">1_1980_s5.tif</Document> <Document Doc_No="7" Subject="s6" path="ta3amime\1980\7_1980.tif">7_1980_s6.tif</Document> <Document Doc_No="4" Subject="s7" path="ta3amime\1980\4_1980.tif">4_1980_s7.tif</Document> </year> </book> <book name="b2"> <year date="1979"> <Document Doc_No="8" Subject="s8" path="ta3amime\1979\8_1979.tif">8_1979_s8.tif</Document> <Document Doc_No="7" Subject="s9" path="ta3amime\1979\7_1979.tif">7_1979_s9.tif</Document> </year> <year date="1980"> <Document Doc_No="9" Subject="s10" path="ta3amime\1980\9_1980.tif">9_1980_s10.tif</Document> <Document Doc_No="1" Subject="s11" path="ta3amime\1980\1_1980.tif">1_1980_s11.tif</Document> <Document Doc_No="8" Subject="s12" path="ta3amime\1980\8_1980.tif">8_1980_s12.tif</Document> <Document Doc_No="14" Subject="s13" path="ta3amime\1980\14_1980.tif">14_1980_s13.tif</Document> <Document Doc_No="16" Subject="s14" path="ta3amime\1980\16_1980.tif">16_1980_s14.tif</Document> </year> </books> searchindex.js Code: window.onload = loadIndex; function loadIndex() { // load indexfile // most current browsers support document.implementation if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.load("index.xml"); } // MSIE uses ActiveX else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("index.xml"); } } // What would be the searchIndex() function ????? // Result in a table Similar TutorialsMy code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> I found this line in one of the scripts on javascript.kit <code> if(document.layers|| document.getElementById|| document.all) </code> Could someone give me an idea on why this line would be used in a code? Thank you very much In this case, Let's take Google Search as example: The code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. This code is used in Fiddler(It's a Man-in-the-middle proxy) Code: if (oSession.uriContains("&q=")) // oSession is a Fiddler object session // uriContains() function, checks for case-insensitive string from the URI { var str = oSession.fullUrl; var sAppend = "test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "&q=","&q="+sAppend); } } For those who are confused, It says, If &q= is present in the URI, replace/append &q= with &q=test1+test2+test3 Problem: It appends test1+test2+test3 instantly, when it sees &q= in the URL. Basically, how do I make it wait until I click the submit/search button Thank you. Update: I heard about Onsubmit() event, but not really familiar with it. How do I use it? like, should I go to google source page and edit the form id? Also, Any other methods besides Onsubmit()? Hi experts, is it possible via Javascript to search certain websites with certain keywords without having to use specific search engines? example search only the following: 1. www.yyy.com 2. www.aaa.com 3. www.zzz.com for the keyword "Laminat" and open the sites accordingly. thx Hi Everyone! I have a website that I'm designing where I have the need to search multiple sites at specific times. By this I mean that In some cases, we would want to search only the internet using google, or only search the site that I've created (which currently uses the jse_search.js solution), or only our company's website. I currently have four different search boxes that will search either the internet, the internal site, a separate internal site, or a third-party website, which all working fine. The problem is that the search boxes take up quite a bit of space, and the layout is becoming cumbersome. Is there a way in Javascript I could use a single search box and a drop-down list to select which method to use? The code I'm currently using is below. With the exception of the Google search function, I've modified some of the site names to general site names and paths to preserve the company's anonymity: Code in the <head> tag: Code: <script language="JavaScript1.3" type="text/javascript" src="jse_form.js"> </script> Code in the <body> tag: Code: <!--Begin Internal Site Search 1!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td><form name="jse_Form" onsubmit="search_form(jse_Form);return false"> <input type="text" name="d" size="30"> </tr></td> <tr><td> <input type="button" value="Internal Site Search 1" onclick="search_form(jse_Form)"> </form> </tr></td> </table> <!--End Internal Site Search 1!--> <!--Begin Internal Site Search 2!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <!--webbot bot="Search" S-Index="all" S-Fields S-Text="Search for:" I-Size="20" S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%Y" TAG="BODY" b-useindexserver="1" startspan --> <form action="http://sitesearch2.idq" method="POST"><input type="text" name="UserRestriction" size="30" value> </tr></td> <tr><td style="text-align: center;"> <input type="submit" value="Internal Site Search 2"></form> </form> <!--webbot bot="Search" i-checksum="4210" endspan --> </td></tr> </table> </div> <!--End Internal Site Search!--> <!--Begin Google Search!--> <form method="get" action="http://www.google.com/search"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input type="text" name="q" size="30" maxlength="233" value="" /> </tr></td> <tr><td align="center"> <input type="submit" value="Google Search" /></td></tr> </table> </div> </form> <!--End Google Search!--> <!--Begin Third Party Search!--> <form id="keywordSearchForm" method="get" action="http://www.site3.html"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input class="input" type="text" name="keyword" size="30" /> </tr></td> <tr><td align="center"> <input type="hidden" name="origin" value="keywordsearch" /><input id="go" class="button" tabindex="0" type="submit" value="Third Party Search" /> </td></tr> </table> </div> </form> <!--End Third Party Site Search!--> I'm working on a website that will basically embed a widget/frame sent by a handler into a user's current page. The user basically adds a script tag to where they would like the HTML to be. The script tag has their settings and is basically a document.write that calls all the code that we want displayed. So here's my problem. We have a map that we need to add in a specific section, and to get the map we have to call another script tag. So we end up having a script tag (map) embedded in another script tag (the code for the widget/frame) or we end up having to document.write inside a document.write. Now this works just fine and as expected in Firefox, Safari, and Chrome. However, Internet Explorer and Opera wait until the first document.write is completely finished before calling the embedded one. Of course the problem with this, is that it takes the map out of the document's flow and just appends it to the bottom left of the page. Since the rest of the page has already been called, there's no way to move the interior "map" script. Any ideas? Basically just trying to figure out how (if even possible) to render an embedded script tag in Internet Explorer and be able to place it properly. I've tried everything that I can think of, including AJAX and Google's unescape script. Any suggestions, I'd greatly appreciate it. Or even if you've encountered a similar problem, and know that it just isn't possible in IE or Opera, that would be fine too. Thanks in advance! Hello people. I'm looking to create a simple search engine capable of searching multiple search engines simultaneously together (e.g. Google, Bing, Yahoo, etc.) and then displaying the results below for all sites on the same page. I don't want each search engine results page opening up in individual windows or anything, nor do I want people to have to manually select the search engine to search with. Just a single page where a user types in something, pressed [Enter] and then presented with all results from multiple sites on one page (without duplicates). I'm also looking to do this with image and torrent sites, etc. How would I go about doing this? Thanks a million guys. You have bigger brains than me. Code: document.getElemetById... is that it, or could be somehow done: Code: anyElement.getElemetById... ? Tryed and it did not work. Hi, I need to open a PDF file via a web page. Basically, I want to have a textbox where I type in a filename and then click submit and it will open that document. For example, I need to open a PDF document... I need to have a text box where I can input "test1" for example, click "GO" and it will add the "C:/test/" + textbox value + ".pdf" and open it in the browser. I could do it in PHP but this is going to run on a local machine with no serverside so I assume JS will be the way forward. Any ideas? Many Thanks MJFCAD I have a html file and a separate javascript file. The html file contains: <input type="reset" id = "resetButton" /> I want a message to pop up if the reset button is pressed. So in the js file I have: document.getElementById("resetButton").onclick = doAlert; doAlert is a function that simply does: alert("Do you want to reset?"); I know my separate js file is linked correctly because if I just put in alert("hello"); in the js file then it works. But if I use the document.getElementById thing in the js file, then there is an error. The error, according to the error console, says that "resetButton" is null. Can someone help me? thanks! btw, I'm totally new to programming...and I need to do this for my homework assignment I am writing some javascript that when the user clicks on a link, it hides or displays content inside a div tag. I have been trying to add some code that would only allow for one div tag to be displayed at a time. Here is where I originally got the code (http://www.willmaster.com/library/hi...-to-reveal.php) Whenever I run this code I get this error: Code: Error: document.getElementById(months[x]) is null Source File: /resources/default.js Line: 30 This is the JavaScript that runs when the user clicks the link: Code: <!-- function accordion(tid) { var x; var months = new Array(); months[0]="January"; months[1]="February"; months[2]="March"; months[3]="April"; months[4]="May"; months[5]="June"; months[6]="July"; months[7]="August"; months[8]="September"; months[9]="October"; months[10]="November"; months[11]="December"; for (x in months) { document.getElementById((months[x])).style.display = "none"; } if(document.getElementById(tid).style.display == "none") { document.getElementById(tid).style.display = ""; } else { document.getElementById(tid).style.display = "none"; }} //--> Here is where the javascript is activated from PHP Code: <a href=javascript:accordion('$month2');>$month2</a><br /> <div id='$month2' style='display: none';> Hello $month2 </div> Hi, I am trying to create a xml document and load it into a 3rd party function as follows: Quote: var doc = new ActiveXObject('Microsoft.XMLDOM'); // OR var doc = document.implementation.createDocument('', 'xml', null); o.overlayKML('somefile.xml'); // Works perfectly o.overlayKML(doc); // Doesn't work at all, return unsupport error I get to know that the overlayKML (3rd party function) needs to read a physical file with a path and sadly it doesn't support DOM. How can I create a javascript document that mimic a physical file and introduce it into the function? Thanks! Hello everyone. I'm having a little problem with creating a element in internet explorer. The element that I'm creating is a div with a few style attributes to to it. The div is suppose to cover the whole page almost like a black transparent window on the page. However it is not. The messed up part about this is that it works fine in Firefox, google chrome and I'm sure other browsers (though haven't tested) and when I go to apply the div in my actual code as javascript is suppose to when you tell it create it, it works fine. No problems whatsoever... I'm not to sure what I'm doing wrong here and it would be great if I could get some help with this. Thanks Code: function showPhotoUpload() { var overlay = document.createElement("div"); overlay.setAttribute("style","z-index:3; background:#111111; width:100%; height:100%; position:absolute; top:0; opacity:0.5; filter:alpha(opacity:50);"); document.body.appendChild(overlay).lastChild; } I have this nice little piece of code that Bullant (CodingForum Senior Coder) helped me with. And it works flawlessly! I want to put it in the same document twice. I've tried to tweak the code so that each script is unique, but to no avail Both scripts work by themselves, but when placed together on the same page - the first one fails. Here is the test-site where it is being used: http://metrobilia.worldsecuresystems.com/stools.html# Here's what I'm doing (see below): Any help would be greatly appreciated! Code: <head> <link href="/stylesheets/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var picData = [ ['images/template2/fpo1_templ2.jpg','URL_for_one'], ['images/template2/fpo2_templ2.jpg','URL_for_two'], ['images/template2/fpo3_templ2.jpg','URL_for_three'] ]; //preload the images var oPics = []; for(i=0; i < picData.length; i++){ oPics[i] = new Image(); oPics[i].src = picData[i][0]; } function swapImage(obj){ oImgSwap.src = oPics[obj.indx].src; oImgSwap.parentNode.href = picData[obj.indx][1]; } window.onload=function(){ oImgSwap = document.getElementById('imgSwap'); oLinks = document.getElementById('radiobs').getElementsByTagName('a'); for(i=0; i < oLinks.length; i++){ oLinks[i].indx = i; oLinks[i].onclick=function(){ swapImage(this); return false; } } swapImage(oLinks[0]); } </script> <script type="text/javascript"> var picDatab = [ ['images/template2/fpo1_templ2b.jpg','URL_for_one'], ['images/template2/fpo2_templ2b.jpg','URL_for_two'], ['images/template2/fpo3_templ2b.jpg','URL_for_three'] ]; //preload the images var oPicsb = []; for(i=0; i < picDatab.length; i++){ oPicsb[i] = new Image(); oPicsb[i].src = picDatab[i][0]; } function swapImageb(obj){ oImgSwapb.src = oPicsb[obj.indx].src; oImgSwapb.parentNode.href = picDatab[obj.indx][1]; } window.onload=function(){ oImgSwapb = document.getElementById('imgSwapb'); oLinksb = document.getElementById('radiobsb').getElementsByTagName('a'); for(i=0; i < oLinksb.length; i++){ oLinksb[i].indx = i; oLinksb[i].onclick=function(){ swapImageb(this); return false; } } swapImageb(oLinksb[0]); } </script> </head> <div class="graphics_templ2" style="padding-left:217px;"> <div class="selections"> <div> <a href=""> <img src="" id="imgSwap" alt="" /> </a> </div> <div id="radiobs"> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_1_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_2_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_3_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> </div> </div> </div> <div class="graphics_templ2" style="padding-left:15px;"> <div class="selections"> <div> <a href=""> <img src="" id="imgSwapb" alt="" /> </a> </div> <div id="radiobsb"> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_1_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_2_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_3_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> </div> </div> </div> Dear Great Coders, I am having some trouble to get the id of the parent of a document which is iframe1 here. As you can see it the <javascript> is residing in the javascript section. Do mind giving me some ideas? Yes, I know. I can insert the javascript on the top, but believe me i cant for some purpose because I am intergrating many other codes into it. <html> <iframe id="iframe1"> <html> <head> <javascript> </head> <body> </body> </html> </iframe> </html> I'm sorry if this question seem very basic but I just start learning javascript. I would like to display an image but not sure why it is not working. In a nutshell, here's my code Code: <html> <head></head> <body> <script type="text/javascript"> document.writeln("<img src=/"xMark.jpg /" width=25 height=25 >");</script> </body> </html> What is an alternative to document.write? I know I could use <p> in html </p> I would like to use JS though. I hope you can understand my question. I am 14yo and this is not for homework. I just wanna try and learn JS. I read document.write can cause me problems. But all I ever see is: <script type="text/javascript"> document.write("any words"); </script> what alternate could I use? What I'm trying to get are the tag ids separately after I call the callback function. I've been racking my brain for far too long on this one. Here is a shorter version of what I have. I'm using the array's length to count and break into their own lines. How do i get all 9 id="hover_[index]" separately using my array length? PHP Code: var info = Array("bla_1", "bla_2", "bla_3", "bla_4", "bla_5", "bla_6", "bla_7", "bla_8", "bla_9"); function callback(results, status) { if (status == myStatus) { for (var i = 0; i < results.length; i++) { send(results[i]); } } } function send(info) { document.getElementById('results').innerHTML += "<div id='hover_"+info.length+"'>Something</div>"; hover_target = document.getElementById('hover_'+info.length);// how do i get all 9 hover_[index] separately? someEvent.addDomListener(hover_target, 'mouseover', function() { // do something }); } Thank you so much in advance, Frank Hello, I'm new to Javascript. I know how to make a script that when you click on a button it changes a variable. I also know that with document.write I can express this variable but I do not know how to refresh document.write! For example, if I have a var car =3 and when I click on a button car++ (or increases by 1 so it becomes 4 then 5 and so forth depending how many times you click the button) and I write document.write (car), it only shows the 3 and no matter how many times I click on the button, the 3 doesn't change. How can I get the document.write to show the updated variable? Thanks! So I want to have a button that when I click it will change this variable and that number will change live on the page. Hi I am trying to make a function run if the mouse is moved over the document but when using the object onmousemove it seems to run the code even if the mouse is still over then document, how can I make it so if the mouse is over the document but isn't moving then don't run the code but once the mouse moves run the code? This is the code I made to handle the mouse move collections. Code: function onmove(func) { var oldonmove = document.onmousemove; if(typeof document.onmousemove != 'function') { document.onmousemove = func; } else { document.onmousemove = function() { oldonmove(); func(); }; } } And to use it you would do this. Code: <script type="text/javascript"> /* Alert A Message Everytime The User Moves Their Mouse */ onmove(function(){ alert('You Moved!'); }); </script> But with this code it runs even when the user doesn't move their mouse and the notification box pops up every second as the code seems to think a still mouse is a moving mouse. I was thinking about having a run once system but that would mean if the mouse moves it runs once and then if the mouse moves again the code will not run as it has already ran before. If anyone can help me please reply, Thank You. DJCMBear. |