JavaScript - Processing An Opml File And Comparing Node Value To String
I'm having a bit of a problem processing an OPML file to load into a list widget that's included in the WebOS development kit. Say I have an OPML file like:
Code: <opml version="1"> <head> <title>News</title> </head> <body> <outline text="Local News" key="local"> <outline type="link" text="Some local Blog1" URL="http://local1.com"/> <outline type="link" text="Some local Blog2" URL="http://local2.com"/> </outline> <outline text="National News" key="national"> <outline type="link" text="Some national Blog1" URL="http://national1.com"/> <outline type="link" text="Some national Blog2" URL="http://national2.com"/> </outline> <outline type="story" text="Community" URL="http://directlinktostory1.com"/> <outline type="link" text="Classifieds" URL="http://directlinktostory2.com"/> <outline type="link" text="Download More News" URL="http://newsfeed.com/getmore.ashx"/> </body> </opml> I can put each text attribute into the list widget using: Code: var tree = transport.responseXML.getElementsByTagName('outline'); for( var i = 0; i < tree.length; i++ ) { curr = tree[i]; if (!curr.hasChildNodes){ this.title = curr.getAttribute('text'); } this.category_items.push({text: this.title}); } But, what I'd like to do is divide the list into categories. To do this, I'd need to append the text attribute value of the parent node to each of the child nodes under the parent node, and in the process, tell it to push the text attribute values of the childnodes if they exist, and of the parentnodes if they do not have childnodes. So I'd be left with something looking like: Code: Local News: Some local Blog1 Some local Blog2 National News: Some National Blog1 Some National Blog2 Misc: Community Classifieds Download More News I'd also like to be able to compare the value of an attribute such as "Download More News" and have that perform a specific function. Can somebody please point me to some information on grabbing only childnodes where they exist and also comparing the value of an attribute to a string? Thank you, Doc Similar TutorialsHi all, Forgive my ignorance, I'm quite new to Javascript... I'm looking to do two things: the first is to move elements of an array to the next index using a function. I have managed to do this like so: Code: var letters = ['h','i','j','k']; function moveElements(anArray){ var newArray = anArray; newArray.unshift(newArray[newArray.length-1]); newArray.pop(); } moveElements(letters); (this may or not be great, but it seemed to work) ... but I want the original array to reset to its original state if the function is called again (thus producing the same answer as opposed to shifting the elements again). Secondly, and this is the bit I'm really struggling with: I want to compare each letter of a string to elements within an array and display the indices. For instance: Code: var myArray = ['a', 'b', 'c', 'd', 'e', 'f']; var text = 'dead'; Hence I want the result '3,4,0,3'. I know the answer will use for and if statements but I can't wrap my head around it at all. Help would be appreciated, thank you. I have a .c file with many function calls like, say, "ABC ( x, y, z);" My concern is to extract just the function name ABC. My approach is to read the file using streamreader.ReadToEnd(), and find the function name using regular expression \b\w+(\([a-z]*[0-9]*\)\b\w). the function call may be of the form... ABC ( xab, ybc, zbc, hgs );" i.e. the syntax is spread thru multiple lines. in the end i just want the function name ABC. please help me with the regular expression or if there is any other approach. Thank U i was wondering: Has anyone here has used Node.js on a production service, app, or site ? If so, what type of project was it, and how is it working out? I'm building a new media site at work using node, and have been blown away by what i've seen/tested so far. Swapping the LAMP stack for just linux and js has really opened my eyes to just how wrong i had been approaching the back-end for so long. Does anyone else have this experience, or am i the only one getting 1,000X performance increases with node? try serving half a million dynamic pages in one hour at 10% cpu and <20 megs of ram on a 5-year old compaq consumer desktop using php; i dare you... i guess the main question is that it's so literally awesome on the bench, will those number hold once it starts getting used by the public? can someone please help me to find out wahy I cant access the text value within the "author> tag using the following code? I get that "var y" is null. Thanks! Code: Content-type: text/html\n\n <html> <body> <book> <author>Moris</author> </book> <script type="text/javascript"> var x =document.getElementsByTagName("author")[0] var y = x.childNodes[0]; document.write(y.value) </script> </body> </html> I just really needed to know something about the whitespace between nodes in a tree structure. I know that Firefox's, Safari's, Chrome's and Opera's DOM treat the whitespace as a node. I am wondering what nodeType whitespace would return? Thank you all for any help + sugestions. Hello I am trying to iterate out the values of an xml file. I have got the file to load though I have not yet been able to extract the values. Considering that theXml is an xml file and 'coords' are tags containing a coordinate how would I extract the value. Here is the code I am using Code: var coordTags = theXml.getElementsByTagName( 'coords' ); var len =coordTags.length;///this works var coord =coordTags[0].value;///this doesn't work var coord =coordTags[0].text;///this doesn't work var coord =coordTags[0].innerText;///this doesn't work parent.document.receiver.theres.value = coord; I am sure for some of you this is a really simple question so please someone help!! Hi follks, i have a xml like this <t> <country>usa</country> <country>india</country> <country>china</country> <country>russia</country> <country>mexico</country> </t> im passing the node country alone in javascript function js:findcountry(//country) the function is like this findcountry(xmlnodecountry) { } what code i should use to send the node country alone to the javascript function. and how can i read and traverse thru the nodes i used xmlnodecountry.selectnodes but it didnt work. im not getting the node itself in xmlnodecountry Does anyone know of a good tutorial on how to make a good node.js chat? I need a chat that a decent VPS server can handle ~100 simultaneous users with and apparently I should be using node.js but have no experience with it. What should I look at? Thanks! edit: I further identified the problem. Hi, I'm new to JavaScript and I'm having problem with appending a div node returned from a function. Here's where it crashed: Code: var div=document.getElementById("dashboard_secondary_cat_list"); var s=get_secondary_cat_node(attributes); alert("b4 appendin:"+s); div.appendChild(s); alert("done appendin"); alert("done appendin"); never gets called because the previous line crashes. alert("b4 appendin:"+s); shows: b4 appendin:[object HTMLDivElement] In order to better understand the DOM data structure, I am trying to write a JavaScript that will produce something like HTML from the DOM data structure. My current problem is that when I include a <br> tag in my source HTML, it reports that its parent is undefined, and this is breaking my code. So, given the following code, why does the <br> tag report that it's parent is undefined. Code: <html> <head> <title>br.parent</title> <script type="text/javascript"> function brTest() { var jBR = document.getElementsByTagName("br")[0]; alert("<br>.nodeType = " + jBR.nodeType + "\n<br>.nodeName = " + jBR.nodeName + "\n<br>.ParentNode = " + jBR.ParentNode); } </script> </head> <body onload = "brTest();"> <p>Now is <br> the time.</p> </body> </html> Thanks for any help you can provide. Jerry Allow the search function to start anywhere within the name, rather than just at the start (so searching for "icha" would match "Richard". If more than 3 matches are found during the search don't display them just inform the user of the number of matches and suggest they search more precisely. Every time the user enters a "bad command", informs them of how many more they are allowed before they are locked out of the system. Introduce and implement an option to change a user's phone number. Reply With Quote 01-14-2015, 08:34 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts Look he http://www.codingforums.com/rules.htm And read rule 1.5 We do *NOT* do your homework for you. I will bet that the answer you got for "search array string" is too advanced. That is, your instructor will know immediately that it is not your own work. You need to *TRY* to do your homework yourself. If you get stuck on one particular point, where your code almost works but not quite, *THEN* is the time to ask a question. But you need to show your work so far. And, if you can, explain what is not working. ********* On a side note: How the heck is anyone here supposed to be able to help you with this part of the homework: Every time the user enters a "bad command", informs them ... You haven't even told us what a "command" is! If you *are* going to ask for help, you have to give enough information that someone can understand the question. But, again, don't expect help until you can (for example) at least show that your code is TRYING to process a "command". Same applies to Introduce and implement an option to change a user's phone number. You haven't bothered to show the data structure that even *HAS* phone numbers in it! Talk about incomplete information! Hey, guys, my first post here on the forums, I hope this is the right place. This technically uses Javascript + PHP + XML, but the problem is more based on Javascript than the other two. That, and there are 380 people viewing Javascript and 8 people viewing XML, I decided to take the path of lesser resistance. Also, the code I used, I'm sure there are a million shortcuts that could be used. So if you can give me suggestions, I would Love to hear them because I'm still learning Javascript + PHP + XML and would be very grateful to learn how I could be more efficient What I'm creating is a Form that takes variables from an XML for users to fill out. Users can choose between products, and then when the product is clicked, it loads the options from an Array within the XML so... The question is Products Load from an Array Options Load from the chosen Products? I'm thinking this can be done two ways. Maybe a separate XML can be used for Options but then how would I link each one for each product? Or, can I load the Options in the same XML for each Product and load an array for each Product's Options? --- Later on, I need to figure out how to create a new element for each form the User fills out. IE They finish filling out the options and volume for 20 GI JOES. So it should save those Variables and the User Filled Variables. And then allow you to fill out a new product. Appending to the last form filled out IE 20 GI JOES [Color Red] [Eating Pizza] [Wearing Cowsuits] 12 BARBIES [Color Blue] [Eating Sushi] [Wearing Bearsuits] But I'll do my own reearch for that before I start asking here on how to do that --- This is my Code so far, some of you will recognize it from W3 Schools --- Code: JS oldTextAry = new Array(); var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET","data.xml",false); xmlDoc.send(""); xmlDoc=xmlDoc.responseXML; } else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("data.xml"); } var x=xmlDoc.getElementsByTagName("PR");i=0; var y=xmlDoc.getElementsByTagName("OPTION");j=0; var z=xmlDoc.getElementsByTagName("OPT");k=0; var enl; Above Code, calls on data.xml in the same folder. It then creates an array from the XML for <PR> <OPTION> and <OPT>. In the XML. It's... Code: XML <PRODUCT> <PR> <TITLE>Title goes here</TITLE> <IMG>jpg html for image goes here</IMG> <ENL>jpg html for high res image goes here</ENL> <LINK>a link if needed</LINK> <INFO>more info if needed</INFO> <OPTION> <OPT>hearts</OPT> <OPT>stars</OPT> <OPT>horseshoes</OPT> <OPT>clovers</OPT> <OPT>balloons</OPT> </OPTION> </PR> <PR> <TITLE>Title goes here</TITLE> <IMG>jpg html for image goes here</IMG> <ENL>jpg html for high res image goes here</ENL> <LINK>a link if needed</LINK> <INFO>more info if needed</INFO> <OPTION> <OPT>hearts</OPT> <OPT>stars</OPT> <OPT>horseshoes</OPT> <OPT>clovers</OPT> <OPT>balloons</OPT> </OPTION> </PR></PRODUCT> The OPT is what I want to load as an array. How could I do that? So continuing with the JS code... Code: function productnext(){if (i<x.length-5) { i++; productline();return false; }} function productprevious(){if (i>0) { i--; productline();return false; }} function productline(){ ttl1=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl2=(x[i+1].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl3=(x[i+2].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl4=(x[i+3].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl5=(x[i+4].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); img1=(x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img2=(x[i+1].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img3=(x[i+2].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img4=(x[i+3].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img5=(x[i+4].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); lnk1=(x[i].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk2=(x[i+1].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk3=(x[i+2].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk4=(x[i+3].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk5=(x[i+4].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); inf1=(x[i].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf2=(x[i+1].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf3=(x[i+2].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf4=(x[i+3].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf5=(x[i+4].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); opt1=(y[j].getElementsByTagName("OPT")[0].childNodes[0].nodeValue); opt2=(y[j+1].getElementsByTagName("OPT")[1].childNodes[0].nodeValue); opt3=(y[j+2].getElementsByTagName("OPT")[2].childNodes[0].nodeValue); opt4=(y[j+3].getElementsByTagName("OPT")[3].childNodes[0].nodeValue); opt5=(y[j+4].getElementsByTagName("OPT")[4].childNodes[0].nodeValue); enl1=(x[i].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl2=(x[i+1].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl3=(x[i+2].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl4=(x[i+3].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl5=(x[i+4].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); The first two functions are for a list in the PHP. The rest of the code gives the first five products into respective variables for the PHP to use. Code: PHP <td width="25" rowspan="3"><a title="<b>Previous Product</b><br><br>Click to Scroll the product list left" onclick="productprevious();" style="cursor:pointer"><img src='prodprev.jpg' width="25" height="170"></a></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR1'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR2'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR3'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR4'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR5'></div></td> <td> </td> <td width="25" rowspan="3"><a title="<b>Next Product</b><br><br>Click to Scroll the product list right" onclick="productnext();" style="cursor:pointer"><img src='prodnext.jpg' width="25" height="170"></a></td> It's a line for five products. When people hit the Next button, it moves the Array one product over. And previous button does vice versa. Code: JS document.getElementById("PR1").innerHTML="<a href='javascript:void();' onClick='picture1();'><img src='"+img1+"' height=120 width=120></a>"; document.getElementById("PR2").innerHTML="<a href='javascript:void();' onClick='picture2();'><img src='"+img2+"' height=120 width=120></a>"; document.getElementById("PR3").innerHTML="<a href='javascript:void();' onClick='picture3();'><img src='"+img3+"' height=120 width=120></a>"; document.getElementById("PR4").innerHTML="<a href='javascript:void();' onClick='picture4();'><img src='"+img4+"' height=120 width=120></a>"; document.getElementById("PR5").innerHTML="<a href='javascript:void();' onClick='picture5();'><img src='"+img5+"' height=120 width=120></a>"; document.getElementById("PT1").innerHTML="<a href='javascript:void();' onClick='picture1();'>"+ttl1+"</a>"; document.getElementById("PT2").innerHTML="<a href='javascript:void();' onClick='picture2();'>"+ttl2+"</a>"; document.getElementById("PT3").innerHTML="<a href='javascript:void();' onClick='picture3();'>"+ttl3+"</a>"; document.getElementById("PT4").innerHTML="<a href='javascript:void();' onClick='picture4();'>"+ttl4+"</a>"; document.getElementById("PT5").innerHTML="<a href='javascript:void();' onClick='picture5();'>"+ttl5+"</a>"; return false;} This code places the products into the respective list. PR1 gets IMG1. This is also where I wonder if it could be more efficient, because I'm copying things five times in a row. There's got to be a better way to do that. Whenever it's clicked it operates a function called picture#() corresponding to the button. Once again... Must be a more efficient way. Code: function picture1() {document.getElementById('PI').innerHTML="<img src="+img1+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl1; /*test area, delete when done*/enl=enl1;document.getElementById("E").innerHTML=enl;} function picture2() {document.getElementById('PI').innerHTML="<img src="+img2+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl2; /*test area, delete when done*/enl=enl2;document.getElementById("E").innerHTML=enl;} function picture3() {document.getElementById('PI').innerHTML="<img src="+img3+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl3; /*test area, delete when done*/enl=enl3;document.getElementById("E").innerHTML=enl;} function picture4() {document.getElementById('PI').innerHTML="<img src="+img4+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl4; /*test area, delete when done*/enl=enl4;document.getElementById("E").innerHTML=enl;} function picture5() {document.getElementById('PI').innerHTML="<img src="+img5+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl5; /*test area, delete when done*/enl=enl5;document.getElementById("E").innerHTML=enl;} Above, places that picture into "PI" and gets the title and places it into "PTT" --- I was hoping to create another list. EXACTLY like I have here. Where the User can hit Next and Previous, using Options Loaded from an Array within the Array of Products. Is making a new XML with options the only way to do this? If that's the case, how do I associate each product with their options? Hey guys..... I've worked out how to get the value from a select option tag, but can't work out how to get the text inside the option tags. Here is the code I am using to get the value attribute from the option tag.. PHP Code: // Set the search results box var cats = document.getElementById('cat_list'); // Loop through categories from the search results select box for (i = 0; i < cats.length; i++) { // Check if the cat is selected if (cats.childNodes[i].selected == true) { // Set this category's values to some variables var cat_id = cats.childNodes[i].getAttribute('value'); } } Thanks! I'm beginner, and there is a task in exam to change inner content of the second child node. Can't get, please help or maybe link to an article how to do it, because I can't find anything in my study book; edit: is this correct? function SetUpTranslation() { var phrases = document.getElementsByTagName('p'); for (var i=0; i < p.attributes.length; i++){ phrases.secondNode.innerHTML=french[i]; element.onclick=swapFE(phrases.secondNode); element.onmouseup=swapFE(phrases.secondNode); } } Hi, im having a little difficulty checking if an XML node has a value, here the code: var Divs=new Array("artist","bio","img","date","tickets","venue","street","city","country","headliner"); xmlDoc=xmlhttp.responseXML; for ( nodes in Divs ) { if(!xmlDoc.getElementsByTagName(Divs[nodes])[0].childNodes[0].nodeValue) { } else { document.getElementById(Divs[nodes]).innerHTML= xmlDoc.getElementsByTagName(Divs[nodes])[0].childNodes[0].nodeValue+"<br>"; } } This always throws up the error: document.getElementById(Divs[nodes]) is null ive tried putting the xmlDoc in a variable then checking if its null but no luck, also tried the same method against "undefined" but no luck either. Would be greatful if anyone has any suggestions. Thanks, Tom. Hi I discovered something weird that happend to me when trying to add a javascript created table to the document.body. Basically it doesn't add it in IE, but works fine in FF. Actually it does add it in IE, but only shows up if I add a <br/> later in a new statement... What?!?! try my code to see what is going on. (works fine in FF, does bad thing in IE) I tried to narrow the code i was working with down to basics and still have the glitch happen so maybe it's just something wrong with this code, but i couldn't pinpoint it. Also, it's only when i do document.body.appendChild(), not document.body.innerHTML += entireMassiveElement.innerHTML; I need it to work in both browsers with the appendChild() method, because innerHTML is much slower. Any advice appreciated! Thanks! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Interace v1.0</title> <style type="text/css"> /****************** * --Panel Style ******************/ .panel { } .panel table td {padding: 0px;} .panel_corner { background-color: #00c0ff; background-repeat: no-repeat; width: 3px; height: 3px; } .panel_sideX {height: 3px; background-color: #00c0ff; background-repeat: repeat-x;} .panel_sideY {width: 3px; background-color: #00c0ff; background-repeat: repeat-y;} .panel_topLeft {background-position: 0px 0px;} .panel_topRight {background-position: -3px 0px;} .panel_bottomLeft {background-position: -0px -3px;} .panel_bottomRight {background-position: -3px -3px;} .panel_top {background-position: -3px -6px;} .panel_right {background-position: -3px 0px;} .panel_left {background-position: 0px 0px;} .panel_bottom {background-position: -3px -9px;} .panel_main { background-color: #00c0ff; } .panel_titlebar { color: #ffffff; font-family: verdana; font-size: 10pt; padding: 3px; padding-top: 0px; overflow: hidden; /* display: none; */ } .panel_title { float: left; height: 18px; overflow: hidden; } .panel_buttons { float: right; } .panel_toolbar { background-color: #444444; color: #eeeeee; font-family: verdana; font-size: 10pt; padding: 3px; overflow: hidden; display: none; } .panel_content { overflow: auto; font-family: arial; color: #eeeeee; font-size: 7pt; font-weight: bold; padding: 10px; border: 1px inset #cccccc; background-color: #444444; } </style> <!--///////////////////////////////////--> <script type="text/javascript"> function makeElement() { var layout = document.createElement("table"); //the table that is the basic layout var top = document.createElement("tr"); var tl = document.createElement("td"); top.appendChild(tl); var tc = document.createElement("td"); top.appendChild(tc); var tr = document.createElement("td"); top.appendChild(tr); var middle = document.createElement("tr"); var ml = document.createElement("td"); middle.appendChild(ml); var mc = document.createElement("td"); middle.appendChild(mc); var mr = document.createElement("td"); middle.appendChild(mr); var bottom = document.createElement("tr"); var bl = document.createElement("td"); bottom.appendChild(bl); var bc = document.createElement("td"); bottom.appendChild(bc); var br = document.createElement("td"); bottom.appendChild(br); layout.appendChild(top); layout.appendChild(middle); layout.appendChild(bottom); layout.style.borderCollapse = "collapse"; tl.className = "panel_corner panel_topLeft"; tc.className = "panel_sideX panel_top"; tr.className = "panel_corner panel_topRight"; tl.style.padding = "0px"; tc.style.padding = "0px"; tr.style.padding = "0px"; ml.className = "panel_sideY panel_left"; mc.className = ""; mr.className = "panel_sideY panel_right"; ml.style.padding = "0px"; mc.style.padding = "0px"; mr.style.padding = "0px"; bl.className = "panel_corner panel_bottomLeft"; bc.className = "panel_sideX panel_bottom"; br.className = "panel_corner panel_bottomRight"; bl.style.padding = "0px"; bc.style.padding = "0px"; br.style.padding = "0px"; //-- Set up the cursors for the bottom, right, and bottomright sides to resize mr.style.cursor = "e-resize"; bc.style.cursor = "s-resize"; // --Now create the internal structure, titlebar, toolbar, content area var main = document.createElement("div"); var titlebar = document.createElement("div"); var toolbar = document.createElement("div"); var content = document.createElement("div"); content.innerHTML = "success!"; main.appendChild(titlebar); main.appendChild(toolbar); main.appendChild(content); mc.appendChild(main); main.className = "panel_main"; titlebar.className = "panel_titlebar"; toolbar.className = "panel_toolbar"; content.className = "panel_content"; //-- create the titlebar internals, title, buttons, cleardiv var title = document.createElement("div"); var buttons = document.createElement("div"); var clear = document.createElement("div"); titlebar.appendChild(title); titlebar.appendChild(buttons); titlebar.appendChild(clear); clear.style.clear = "both"; title.className = "panel_title"; buttons.className = "panel_buttons"; main.style.width = "200px"; return layout; } function go(select) { var stuff = makeElement(); if(select == 1) { //-- Add everything to the container document.body.appendChild(stuff); } else if (select == 2) { //-- Add everything to the container //layout is a table, but innerHTML only returns the inner, so i just added on the outer tags. document.body.innerHTML += ('<table cellpadding="0" cellspacing="0">' + stuff.innerHTML + '</table>'); } //document.body.innerHTML += "<br/>"; } </script> </head> <body> <input type="button" value="test append Element" onclick="go(1);"/><input type="button" value="test innerHTML add" onclick="go(2);"/> <body> </html> Hey, I'm new here, have always browsed but never created an account until now. I am an avid PHP programming but Javascript is not my thing. I am working on a module for a website of mine and I can't seem to figure thing one thing out. I have a module that competes a telephone verification and I would normally just use PHP but I am limited to the fact that I cannot alter or refresh the web page. I have a javascript module currently that people click a button and AJAX calls a serverside PHP script (which outputs a a random 4 digit code that it tells the user). That random 4 digit code is assigned to a global variable and then updating using the code ... verification_code=page_request.responseText (Output of my PHP document through AJAX) And then I have a textbox in which users input the 4 digit code (that the telephone script tells them). I have a variable called verification_input which is equal to the value of the textbox. I've been debugging this for awile now, If i write something like this Code: alert (verification_input + " code: " + verification_code); if(verification_code==verification_input){ alert('success?'); } everything works except for the success alert. The only weird thing I notice is the output of the first alert will be something like 2637 code : 2637 which the second set of numbers being on the next line. Any help would be appreciated. It's probably something simple Hello all, i'm looking for a way to check if the name of the page is equal to a link inside the page being checked. for instance: inside the address bar: http://www.mysite.test.html <body> <ul> <li><a href="test.html"></a></li> <li><a href="test1.html"></a></li> <li><a href="test2.html"></a></li> <li><a href="test3.html"></a></li> </body> please advise. thanks, jav I need to write a script that will search for a style attribute that matches "top: 10px;". If a match is found, it will then edit the value of that input box to "hello". So for example a webpage has: Code: <input style="top: 1px;" maxlength="20" type="text"> <input style="top: 100px;" maxlength="20" type="text"> <input style="top: 10px;" maxlength="20" type="text"> The script would edit the value of the 3rd one to "hello". I'm a beginner to javascript so my code may not make sense but bear with me please. Code: var styles = document.getElementsByTagName("input").attributes.getNamedItem("Style") for (var i = 0; i < styles.length; ++i){ if (styles.value == "top: 179px; left: 348px; width: 222px;"){styles.value="hello"} } I don't know if JavaScript is the best choice for this or maybe just Java but i want to create something were I can compare a list of names and their picks with a correct list. For example lets say this is the list of peoples picks... Code: Dan Slota New York Jets Dan Slota Cincinnati Bengals Dan Slota Pittsburgh Steelers Dan Slota Denver Broncos Dan Slota Green Bay Packers Dan Slota Atlanta Falcons Dan Slota New Orleans Saints Dan Slota Seattle Seahawks Dan Slota Indianapolis Colts Dan Slota Houston Texans Dan Slota Philadelphia Eagles Dan Slota San Diego Chargers Dan Slota Chicago Bears Dan Slota New England Patriots Danielle rossi New York Jets Danielle rossi Cincinnati Bengals Danielle rossi Baltimore Ravens Danielle rossi Tennessee Titans Danielle rossi Green Bay Packers Danielle rossi Atlanta Falcons Danielle rossi New Orleans Saints Danielle rossi St. Louis Rams Danielle rossi Indianapolis Colts Danielle rossi Houston Texans Danielle rossi Philadelphia Eagles Danielle rossi San Diego Chargers Danielle rossi Chicago Bears Danielle rossi Miami Dolphins David Fleischer New York Jets David Fleischer Cincinnati Bengals David Fleischer Baltimore Ravens David Fleischer Denver Broncos David Fleischer Green Bay Packers David Fleischer Atlanta Falcons David Fleischer New Orleans Saints David Fleischer Seattle Seahawks David Fleischer Indianapolis Colts David Fleischer Oakland Raiders David Fleischer Philadelphia Eagles David Fleischer San Diego Chargers David Fleischer New York Giants David Fleischer Miami Dolphins and here is the master list of the correct picks ... Code: Master List New York Jets Master List Cleveland Browns Master List Baltimore Ravens Master List Tennessee Titans Master List Green Bay Packers Master List Atlanta Falcons Master List New Orleans Saints Master List Seattle Seahawks Master List Indianapolis Colts Master List Houston Texans Master List Philadelphia Eagles Master List San Diego Chargers Master List New York Giants Master List Miami Dolphins After the user list is compared to the master list i need it to say the results of each user for example Code: David Fleischer 8 correct Danielle Rossi 9 correct Dan Slota 5 correct . . Sam Adams 2 correct [/CODE] What would be a good way of doing this? Any help would be appreciated Thanks. |