JavaScript - Calling A Subset Of An Xml Doc
I'm using an XMLHttpRequest to call an XML document.
Code: xmlhttp.open("GET","gallery.xml",false); xmlhttp.send(); var xmlDoc = xmlhttp.responseXML; var x = xmlDoc.getElementsByTagName("photo"); How do I retrieve a subset of the photo elements - for example, retrieve only those with "insect" in the category node? Similar TutorialsI need to create a form button named Create Resume. When clicked this button should call a function that generates a new Web page displaying a resume based on the user input. I am supposed to use the document.write() method to populate a newly generated Web page with all of the XHTML elements, formatting and variable values needed to produce the desired output in Web (.htm) format. I was hoping to get some guidance on how to accomplish this final step on my project. Any help would be greatly appreciated! KM <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Web 115 Final Project</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <script type="text/javascript" src="projectjs.js"> </script> <hr align="center" width="60%" /> </br> <script type="text/javascript"> document.write("<span style=\"font-family:garamond; text-align:center;font-size: 30px;\"> <p><b>Build Your Resume</b></p><\/span>"); </script> <form name="resume" method="get"> <p><input type="text" value="Enter your full name" size="50"/> </p><p> <input type="text" value="Enter your address" size="150"/> </p><p> <input type="text" value="Enter your phone number" size="50"/> </p><p> <input type="text" value="Enter your e-mail address" size="50"/> </p> <script language = "Javascript"> function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("Invalid E-mail ID") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at) ==lstr){ alert("Invalid E-mail ID") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot) ==lstr){ alert("Invalid E-mail ID") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Invalid E-mail ID") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Invalid E-mail ID") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Invalid E-mail ID") return false } if (str.indexOf(" ")!=-1){ alert("Invalid E-mail ID") return false } return true } function ValidateForm(){ var emailID=document.resume if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter your Email ID") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } </script> <p> <textarea id="tarea" cols="75" rows="4">Enter your personal information </textarea></p><p> <textarea id="tarea" cols="75" rows="4">Enter your career objectives </textarea></p><p> <textarea id="tarea" cols="75" rows="4">Enter your educational background </textarea></p><p> <input type="text" value="Most recent employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Most recent employment experience</textarea> </p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <textarea id="tarea" cols="75" rows="4">Character References</textarea></p><p> <textarea id="tarea" cols="75" rows="4">Business References</textarea></p></br> <input type="button" name="push_button" value="Create Resume"/> </form> </body> </html> New here. The issue is this: I am trying to display two clocks. I used the javascript clock generator (http://rainbow.arch.scriptmania.com/...generator.html) to create both clocks. However, the same code to place in the html was given to call each clock; <script language="JavaScript">displayTime();</script>. Below is the code for both clocks. What can be changed so that each clock displays on my website? Clock 1: function timeSource(){ x=new Date(timeNow().getUTCFullYear(),timeNow().getUTCMonth(),timeNow().getUTCDate(),timeNow().getUTCHours (),timeNow().getUTCMinutes(),timeNow().getUTCSeconds()); x.setTime(x.getTime()+10800000); return x; } function timeNow(){ return new Date(); } function leadingZero(x){ return (x>9)?x:'0'+x; } function twelveHour(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } function displayOnTime(){ if(fr==0){ fr=1; document.write('<font size=1 face=verdana><b><span id="tP">'+eval(outputTime)+'</span></b></font>'); } document.getElementById('tP').innerHTML=eval(outputTime); setTimeout('displayOnTime()',1000); } function amPMsymbol(x){ return (x>11)?'pm':'am'; } function fixYear4(x){ return (x<500)?x+1900:x; } var dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var monthNames=new Array('January','February','March','April','May','June','July','August','September','October','Novem ber','December'); var fr=0; var outputTime1="dayNames[timeSource().getDay()]+' '+timeSource().getDate()+' '+monthNames[timeSource().getMonth()]+' '+fixYear4(timeSource().getYear())+' '+':'+':'+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(tim eSource().getSeconds())+' '+amPMsymbol(timeSource().getHours())"; Clock 2: function timeSource(){ x=new Date(timeNow().getUTCFullYear(),timeNow().getUTCMonth(),timeNow().getUTCDate(),timeNow().getUTCHours (),timeNow().getUTCMinutes(),timeNow().getUTCSeconds()); x.setTime(x.getTime()+daylightSaving()-18000000); return x; } function timeNow(){ return new Date(); } function daylightSaving(){ return ((timeNow().getTime()>findDay(0,2,3,2).getTime())&&(timeNow().getTime()<findDay(0,10,3,1).getTime()) )?3600000:0; } function findDay(d,m,h,p){ var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(timeNow().getUTCFullYear(),nm,1,h,0,0),dOff=0; if(p<0){ x.setTime(x.getTime()-86400000); } if(x.getDay()!=d){ dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d); if(p<0&&dOff>0){ week-=7; } if(p>0&&dOff<0){ week+=7; } x.setTime(x.getTime()+((dOff+week)*86400000)); } return x; } function leadingZero(x){ return (x>9)?x:'0'+x; } function twelveHour(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } function displayTime(){ if(fr==0){ fr=1; document.write('<font size=2 face=Arial><b><span id="tP">'+eval(outputTime)+'</span></b></font>'); } document.getElementById('tP').innerHTML=eval(outputTime); setTimeout('displayTime()',1000); } function amPMsymbol(x){ return (x>11)?'pm':'am'; } function fixYear4(x){ return (x<500)?x+1900:x; } var dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var monthNames=new Array('January','February','March','April','May','June','July','August','September','October','Novem ber','December'); var fr=0; var outputTime="dayNames[timeSource().getDay()]+' '+timeSource().getDate()+' '+monthNames[timeSource().getMonth()]+' '+fixYear4(timeSource().getYear())+' '+':'+':'+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(tim eSource().getSeconds())+' '+amPMsymbol(timeSource().getHours())"; I've done a lot of work only to be stuck here at this problem. someone please help: Using the today variable as the parameter value, call the showDateTime() function and store the value returned by the function in the thisDay field of the eventform Web form. what exactly is this asking me to do? would you provide examples please? thanks in advance!@ I would like to call a function within a function. Is this even possible?? When I do this I get "undefined" Here's my code: Code: <html> <head> <script type="text/javascript"> function product(a,b){ total = a*b; display(total); } function display(num){ return num; } </script> </head> <body> <h1>This text I do NOT want to be erased.</h1> <a href="http://google.com" target="_blank">Total: </a> <script type="text/javascript"> product(3,4); document.write(display()); </script> </body> </html> I know you can just return in the first function, "product()" but I would like to do something else in my second function "display()" then return a value. thanks I am in a class that is right now creating an online quiz that is also displays time. The part I am running into a wall right now is "Call the runClock() function every second, storing the ID of this timed-interval command in the clockId variable." I am unsure how to call it every second. Also, how would I call a function within a function? Here is my code so far: <link href="quiz.css" rel="stylesheet" type="text/css" /> <script src="functions.js" type="text/javascript"></script> <script type="text/javascript"> var seconds = 0 var clockID = function runClock() { clockID = seconds++; document.getElementById("quizclock").value = seconds; } function startClock() { return showQuiz; } </script> </head> in HTML you can call CSS Code: <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <tr><td class="cssHere">Display</td></tr> can you even call CSS in javascript? Code: document.writeln("<tr><td class="cssHere">" + Display + "</td></tr>"); if so how do you even call the "style.css" thanks So I'm new around here, and to web dev in general, but I've got a (hopefully) short question. I am trying to call a function (nextMonth()) every second from the time that the cycle method gets called, until it is called again. As of now I am trying to use setInterval, (and I previously tried with setTimeout and using a callback argument but maybe I wasn't doing that properly). The problem is that after running the cycle() method for 5 or 6 seconds, the entire browser freezes up and you have to kill it and restart it. Here is my code as of now: Code: function cycle() { if(CYCLEINT != null) //STOP THE CYCLE LOOP { window.clearInterval(CYCLEINT); CYCLEINT = null; document.getElementById("cycle").innerHTML = "Cycle Months"; } else //LOOP IS NOT RUNNING, INITIATE AND CONTINUE INTERVAL. { CYCLEINT = self.setInterval("nextMonth()", 1000); document.getElementById("cycle").innerHTML = "Pause"; } } function prevMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal > 1) { dVal--; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } } function nextMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal < dateMax) { dVal++; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } if(CYCLEINT != null && dVal >= dateMax) { cycle(); } } Hello, I am new to using Javascript and have some experience with HTML and CSS. I am trying to use Javascript to display an image based on a value. I have the image positions in my .css. Just to make it easy if my var x=0 i want to call the "position 1" div, or else i want to call the "position 2" div. How can i make this possible. I have positions because i have a background image and i want the different pictures to be in a different location on the background based on the value. Below is my code that I have right now. Thanks for the help. layout.css #layout { position: relative; top:0%; z-inderx:-1; } #date { position: absolute; top:5%; left: 50%; margin-left: -190px; z-index: 1; font-family: calibri; font-size: 44px; font-weight: bold; color:#000000; } #location1 { position: absolute; top:22%; left: 50%; margin-left: -590px; z-index: 1; } #location2 { position: absolute; top:28%; left: 50%; margin-left: -590px; z-index: 1; } Layout.HTML <html> <head> <Title>Layout</title> <link rel"stylesheet" type="text/css" href="layout.css" /> </head> <body> <div id="layout"> <center> <img border="0" src="background.png" width="1200" height="880" /> </center> </div> <div id="date"> 24 OCTOBER </div> <script type="text/javascript"> var x=0; if (x==0) { <div id="location1"> <img border="0" src="picture1.png" width="70" height="60" /> </div> } else { <div id="location2"> <img border="0" src="picture2.png" width="70" height="60" /> </div> } </script> </body> </html> Hi, I'm very new to Javascript and I need some help on calling some existing functions. What i want to do is create a new function to call the first test1 and then call test2 to turn on the checkbox. i hope this isn't confusing. Code: function test1(inStore,onSale,newItem) { var daURL; if (inStore==true) { BSSetStoreOnly(true); daURL="s-2-Online-Store.aspx?ms=bsm1"; if (onSale==true){ daURL+='&SaleOnly=1'; } } else { BSSetStoreOnly(false); daURL="s-1-Our-Products.aspx?ms=bsm1"; if(newItem==true) { daURL+='&NewOnly=1'; } } location=daURL; } function test2() { var pInc; chk=document.getElementById("chkAll"); pInc=readCookie("overrideURL"); if (pInc==null) { pInc=0; } if (pInc==0) { chk.checked=false; } else { chk.checked=true; } } function callingTest1Test2 { } Can I clean up the header section on some of my pages by putting all the javascript stuff in another page, and then using a server side script to assemble the header? If so how do I do this? For example all my pages have the following in the header: <script type="text/javascript" src="css/csshorizontalmenu.js"></script> I want to have this in a seperate file and call with SSI but it doesnt work when I use something like the following: <?php require_once('navigation.php'); ?> Thanks for any help. Hey guys, I'm trying to call the following custom tag: <mvt:item name="category_tree" /> from a JS function: <script language="javascript" type="text/javascript"> <!-- function left_nav_bar () { document.write('Categories:'); document.write('<mvt:item name="category_tree" />'); } //--> </script> But the custom tag is not executing in the browser. Am I calling it wrong from my JS code? Hi, How can i call a javascript alert function from an if condition in PHP? For instance: if (A == B) { CALL alert(); } thanks I am able to do the following; Code: alert(myObject.Income.EESA.Name); However I'm looking at Code: alert(myObject.Income[0].Name); Or even better, not the full name, just "EESA". I need to loop through as you can see at the end of this script what I'm working on. Code: <script type="text/javascript"> var EESARate = 289.3; var DLARate = 111.20; var CARate = 61.35; var SkyCost = 54.75; var PerfectHomeCost = 28.17; var CreditExpertCost = 14.99; var UnitedUtilitiesCost = 8.13; var BTCost = 57.18; var AdobeCCCost = 46.88; var TVLicenceCost = 6.06; var GasCost = 10.00; var ElectricCost = 20.0; var ServerPackageCost = 9.99; var USDValue = 123; //Fetch the value var myObject = { "Income": { "EESA": { "Name": "Enhanced Employment and Support Allowance", "Amount": { "GBP": EESARate, "USD": EESARate * USDValue }, "Frequency": { "When": "14", "Next": "30/10/2014" }, "Description": "", }, "DLA": { "Name": "Disibility Living Allowance", "Amount": { "GBP": DLARate, "USD": DLARate * USDValue }, "Frequency": { "When": "7", "Next": "Wednesday" }, "Description": "", }, "CA": { "Name": "Carers Allowance", "Amount": { "GBP": CARate, "USD": CARate * USDValue }, "Frequency": { "When": "7", "Next": "Saturday" }, "Description": "", }, }, "Bills": { "Sky": { "Name": "Sky", "Amount": { "GBP": SkyCost, "USD": SkyCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, "PerfectHome": { "Name": "Sky", "Amount": { "GBP": PerfectHomeCost, "USD": PerfectHomeCost * USDValue }, "Frequency": { "When": "7", "Next": "Wednesday" }, "Description": "", }, "CreditExpert": { "Name": "Experian Credit Expert", "Amount": { "GBP": CreditExpertCost, "USD": CreditExpertCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, "UnitedUtilities": { "Name": "United utilities", "Amount": { "GBP": UnitedUtilitiesCost, "USD": UnitedUtilitiesCost * USDValue }, "Frequency": { "When": "7", "Next": "Wednesday" }, "Description": "", }, "BT": { "Name": "British Telecomunications", "Amount": { "GBP": BTCost, "USD": BTCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, "AdobeCC": { "Name": "Adobe Creative Cloud Suite", "Amount": { "GBP": AdobeCCCost, "USD": AdobeCCCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, "TVLicence": { "Name": "Television Licence", "Amount": { "GBP": TVLicenceCost, "USD": TVLicenceCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, "Gas": { "Name": "Eon Gas", "Amount": { "GBP": GasCost, "USD": GasCost * USDValue }, "Frequency": { "When": "7", "Next": "Wednesday" }, "Description": "", }, "Electric": { "Name": "Eon Electric", "Amount": { "GBP": ElectricCost, "USD": ElectricCost * USDValue }, "Frequency": { "When": "7", "Next": "Wednesday" }, "Description": "", }, "ServerPackage": { "Name": "1&1 Unlimited Plus (12 mo. term)", "Amount": { "GBP": ServerPackageCost, "USD": ServerPackageCost * USDValue }, "Frequency": { "When": "30", "Next": "XX/XX/XX" }, "Description": "", }, }, }; var IncomeTotal = 0; for (var k in myObject.Income) { if (myObject.Income.hasOwnProperty(k)) { ++IncomeTotal; } } alert(myObject.Income.EESA.Name); document.write('<table>') for(i = 0; i < IncomeTotal; i++){ document.write('<tr>') document.write('<td>row ' + (i+1) + ', column 0</td>') document.write('</tr>') } document.write('</table>') var TotalBills = 0; for (var k in myObject.Bills) { if (myObject.Bills.hasOwnProperty(k)) { ++TotalBills; } } //alert(TotalBills); </script> I almost have the website finished, at least functionally (the complicated backend). It will arguably be one of the coolest history sites on the web. But I am running into some technical problems, and want to ask you about them, as I am at a point where that is my only alternative. First is in the website: http://184.73.182.71/timelines/search2.fwx There is the line: Timeline.loadXML("http://184.73.182.71/14OZH01XY.xml", function(xml, url) { eventSource.loadXML(xml, url); }); This is loading an XML data file into the time-line, and it works fine. The question is, why cant I dynamically load this data from a process, like: Timeline.loadXML("http://184.73.182.71/getdata.php?page=10", function(xml, url) { eventSource.loadXML(xml, url); }); It is returning the exact same thing, yet it dosent work. Somebody suggested the following: eventSource.loadXML(eventSource.loadXMLText(xmlstring,),"http://184.73.182.71/getdata.php?page=10"); But that dosent seem to work either. And can I do the same thing with a script tag, such as: <script src="http://184.73.182.71/getdata.php?page=10" type="text/javascript"></script> Is this illegal? Thanks in advance for looking at this. In here is an example of a frameset im currently working. i have this frameset: http://www.mediafire.com/?75dvswgvelw19a9 what i want is when i select radio button "YES" and click on the "create" button in form1 http://www.mediafire.com/?eld7a1rb21h799e it will pass the value to radio button "ON" in form 2 http://www.mediafire.com/?f0o060cdpyf06ya and will call the function of the radio button "ON" -shows the hidden textarea. And if i select radio button "NO" in form1 and click on "create" button, it will select radio button "OFF" in form 2. help plsssssssss hi i have a sliding vertical menu in my page in the left side and in the right side i have a text say for eg: Home. So when i click on home, i need the left side vertical menu to slide and open and the home in the left side should get highlighted. How do i do this in javascript ???? Pls help!!!! i now have <a href=""javascript:NewCssCal('repaymentdate','ddMMyyyy')""> how can I have this after it calls teh newcsscal and fills in the textbox call another function. (i don't want to add it to newcsscal as that's used in multiple locations and I only need to call this function in 1 location. if a mod views this can you correct the spelling mistake in que to queue in heading please ok so before you look at the code i am using the fightBoss() function to start run the main functions read the comment under fightWithSkillOrRefill......(1) http://pastebin.com/ZjbvevfP when you get to the function useInventoryItemMS(item) the if statment gets stuck not sure if its before or after then but when it gets stuck theres a reload function purposly to stop the script from getting stuck but for some reason its not getting to the if statment to clear the queue to stop the reload and then do the next queue set in the if statment. Hello, so I'm trying to call multiple functions with onClick. It doesnt really work, just wondering why. Advice or tips would be nice, thank you guys for your time. By the way this is a project for school so the comments are for my professor Code: <head> <title>Untitled Document</title> <script type="text/javascript"> //hello, this code doesn't work, I did it piece by piece so the bits work, but when I combined them, it stopped working function texter(newText){ var oldHTML = document.getElementById('outputPrompt').innerHTML; document.getElementById('outputPrompt').innerHTML = newText+"<br />"+oldHTML; console.log(newText); } // texter function from class function menuMain(){ var userInput = document.getElementById('input').value; var mainMenu; if (userInput == "3"){ mainMenu = menuThree(); } else if (userInput== "2") { mainMenu = menuTwo(); } else if (userInput== "1") { mainMenu = menuOne(); } texter(mainMenu) } //going to the functions by calling them function menuOne(){ var userInput = document.getElementById('input').value; if (userInput.length == 0){ texter("You need to enter something in the input box"); } else { texter("the string has been saved"); } } // if the length is equal to zero then there was nothing inputted function menuTwo() { var userInput = document.getElementById('input').value; var theArray = userInput.split(/\s|\n|\r/); //split string into words array i looked up the regex on coding forums //also had help to create this from coding forums var WordsFound = [i]; for (var i=0; i<theArray.length-0; i++) { if (theArray[i].length < 5) { WordsFound.push('eep- '+theArray[i]); } else { if (theArray[i].length > 5) { WordsFound.push(theArrray[i]+' -zzz'); } else { WordsFound.push(theArray[i]); } } } document.getElementById('outputPrompt').innerHTML = WordsFound.join('<br>'); } // if the array length is less than five the word will push it onto the array // vise versa with the array length being more than five //then i join the word with the array function menuThree() { var userInput = document.getElementById('outputPrompt').reset(); } //reset the output function combineFunctions() { menuMain(); menuOne(); menuTwo(); menuThree(); } // combining the functions into one function so i can call it on onclick function cleartext(){ document.getElementById('input').value=""; } </script> </head> <body> <h1>RoboSpeek</h1> <textarea type='text' id='input' onfocus="cleartext()" cols="40"rows="10" wrap="physical"> Please enter 1,2,3 or Exit</textarea><br /> <input type='button' onclick='combineFunctions()' value='submit'/> <p id='outputPrompt'>Please enter 1,2,3 or exit only</b> </p> </body> </html> Code: <form> <input type="button" value="Click!" id="001" /> </form> function one() { window.alert('Hello'); window.alert('World!'); } var varname=document.getElementById("001"); varname.onclick=one; I am not sure if the last line is this example is correct. Should it not be: varname.onclick=one(); Or is it ok to write it either way? Thanks. |