JavaScript - Vary Call Parameter
When calling a javascript file I have written
<script type = "javascript" src = "mycode_2010.js"> However, I would like to replace 2010 with a variable so that for example I can detect the year and load the appropriate code e.g. mycode_2011.js rather than writing a new hard coded html page. Is it possible please? Similar TutorialsI have a good understanding of javascript although I am new to working xml. So I am having a problem getting javascript to recognize that my parameter value in my function call is an attribute in my xml. I called the js function like this: Code: <a href="#" onClick="ebookCategory(marketing);">Marketing</a> Here is my js function: Code: var category; function ebookCategory(category) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","ebook.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName(category); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("bookCover")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue); document.write("</td><td>"); i++; document.write(x[i].getElementsByTagName("bookCover")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue); document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); } // end ebookCategory() Some of the aspects in this function are new to me, xml stuff. Here is my xml setup: Code: <ebook category="marketing"> <bookCover><img src="/millionaire/ebooks/covers/miracle2.jpg" height="150" width="150" /></bookCover> <title>Marketing Miracle</title> </ebook> I appreciate any help in the matter Hi, I am hoping I just need to be pointed in the right direction with this. I have Page1. When Page1 body onloads it uses Ajax to call PartA Within PartA I have a message board so members can write messages which will be sent to my database in PartA[1] and immediately posted for view on to PartA[2]. As I want to have my request to the server updating regularly I want to have PartA[2] on a timed loop to refresh - I do not need the content of PartA[1] to refresh. So the order of events would look like this: Page1 | onload call | v PartA / \ V V PartA[1] PartA[2] (loads once) (constantly refreshes) What I am not sure about is that I have <body> and <head> attributes in Page1 only. I have already used my body onload to call PartA (and can't use it to call PartA[2] before PartA has loaded anyway). I do not want the user to have to click a button or do anything to call up PartA[2]. So my question is how would I get PartA[2] to automatically load within PartA? I hope I have made this clear, but if I haven't let me know and I will try again. Hello there, Could someone tell me how a javascript can get a cookie and use it as a parameter like www.mysite.com?search=COOKIEDATA Thanks you (a) Hi I have this code which works fine: Code: <td class="Content_TD" onclick="_gaq.push(['_trackEvent', 'navigation ', 'link', 'blocks']); window.open('http://www.google.dk/');"> But I dont now the parameters instead of window.open, if I want it to open on top. Can somebody please help me? Thanks in advance Claus Hi I am in doubt if im doing this correct. I have a TD which I have a onclick and a google event tracking code on. But om not shure if I have set it up correct. The () and the , might be wrong..? <td class="Content_TD" onclick="(window.open('http://www.google.com/')), (_gaq.push(['_trackEvent', 'navigation', 'link', 'event']));"> Thanks in advance! I have to use get method (instead of post) for form action but dont want to show the url parameter in the action page url. Anyway to hide or encrypt a form input value after it goes into my database? Code: <form action="actionpage.cfm" method="get"> <input type="text" name="myValue"> <input type="submit" name="submit"> </form> Hi, Im not very good with javascript so I appologize is this is a stupid question. In the code of my gallery software I have this line: <h2 id="item-title">{$theme.item.title|markup|default:" "}</h2> This displays the title of the image. I dont actually want to display the title of the image. However, when I delete this line, the gallery no longer works (in the view photo page, the javascript image loader just says loading). Is there a way to keep this required parameter in, so that my gallery works, but stop it from being displayed on the page? Here is a link to the page (currently ive left the line in) http://www.zombiemod.com/rm/nina2/main.php?g2_itemId=13 I've been staring at this same problem for over a week now. I've worked around it as best as i can but i think it's time to ask someone else for input. I'm trying to pass a value thru an ajax parameter.. that's all. it SHOULD be easy in theory. what i want to do is create a jscript variable then pass that variable as the value for a parameter. php then converts that value to something it can use to finish the rest of my code. As i said it's hindering my webpage progress and i would like to get it fixxed soon so any help would be appreciated. Code: function getSelection() { var selection=document.getElementsById("SelectedItem"); var xmlhttp;//create a var for the obj if (window.XMLHttpRequest)//if requesting an obj... { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { var text = xmlhttp.responseText; addNode(text); } } xmlhttp.open("GET","battle_nin.php?selection",true); xmlhttp.send(null); } //the php snippet $currentjutsu=$_GET[selection]; I could not figure out the answer, and could not find the answer from Google. I have following object PHP Code: ; var obj = function() { ; this.method_1 = function() { ; return this.method_2 } ; this.method_2 = function() { ; return 'my parameter' } } It works. If I want method_2 having parameter, I write it this way: PHP Code: ; var obj = function() { ; this.method_1 = function() { ; return this.method_2 } ; this.method_2 = function(para) { ; return para } } ; var newObj = new obj() ; window.alert(newObj.method_2('my parameter')) It works and returns "my parameter". If I want method_2's parameter to be assigned by method_1, I write it this way: PHP Code: ; var obj = function() { ; this.method_1 = function() { ; return this.method_2('my parameter') } ; this.method_2 = function(para) { ; return para } } It does not work. So, the question is how to assign a parameter of a method by another method? Thanks a lot. I want a URL parameter, like http://www.thatswhyimbroke.com/#tab-1 to be added when a link is clicked. So for example, when I click one of the menu tabs on http://www.thatswhyimbroke.com/, I want a #tab-1 to be added at the end of the URL. If you look now, clicking a new tab adds nothing to the URL because it's pre-loaded. Please let me know if you need more explanation, I'm not sure i'm explaining it correctly. Thanks for any help! Hi, I am learning javascript from a book ("Javascript and JQuery Missing Manual") and one example there sets my head spinning and I can't understand how the script works. I'd be very grateful if someone could write a few words about the aspect I don't understand. Basically it is line seven I don't understand. How is the word question tied to the items in the questions array. I understand the 0 and 1 on line eight and nine and why they focus on the first and second item in the sub-array, but still, how can the word question point to the relevant item in the questions array? Code: var score = 0; var questions = [ ['How many moons does Earth have?', 1], ['How many moons does Saturn have?', 31], ['How many moons does Venus have?', 0] ]; function askQuestion(question) { var answer = prompt(question[0], ''); if (answer == question[1]) { alert('Correct!'); score++; } else { alert('Sorry. The correct answer is ' + question[1]); } } for (i=0; i<questions.length; i++) { askQuestion(questions[i]); } Hi all I'm adding buttons to my google map through a loop. I pass some parameters, and the addButtons() function creates the buttons. How can I pass the "task" for the button to the function? In the addDomListener line below, I'm now writing the function name literally, I'd like find a way with a parameter. Thank you.. Code: // The loop... for (i=0;i<=4;i++) { oCC = addButtons(aCtrls[i],'btnContainerChild'); ... } // The function... function addButtons(cButtonID,cClassName) { var oButton = document.createElement('DIV'); oButton.className=cClassName; oButton.id=cButtonID; //... other settings here... // ===> Here, I'd like to set the click function through a parameter google.maps.event.addDomListener(oButton, 'click', function() {gmapSetCenter(defaultCenter)}); Before any elaboration..plz see the code first. Code: <script> hex1=0 hex2=0 hex3=0 function hexi(id) { if(hex3<255) { hex3=hex3+15; document. getElementById(id) .style.color="rgb("+hex1+","+hex2+","+hex3+")"; setTimeout(" hexi(id) ",20); } } </script> <div id="test" style="width:100%"><h3>John slowly faded into view</h3></div> <button onmouseover=" hexi('test') ">Fade Text</button> Here i don understant why but id="test" doesn't seem to be passed through getElementById(id)....do i need to use some escape character or something? wish i get someone to have a solution.. I'm a perplexed nube, and I can't understand how document.getElementById evaluates to true when no parameter is passed to getElementById. This code alerts 'foo' ... Code: if (document.getElementById) {alert('foo')} else {alert('bar')} Just to double check, this code alerts 'bar' Code: if (!document.getElementById) {alert('foo')} else {alert('bar')} Hi, I have an "offline" html demo of 50+page - so it needs to run on standard html/javascripts... I'm trying to do this: Page A Code: <a href="pageb.html?endpage=pageD.html">Page B.html</a> <a href="pageb.html?endpage=pageE.html">Page B.html</a> <a href="pageb.html?endpage=pageF.html">Page B.html</a> Page B Code: <a href="PageC.html?endpage=(the parameter of page A)">Page C</a> <a href="(the parameter of page A)">End Page</a> Page C Code: <a href="(the parameter of page A)">End Page</a> I've searched for a couple of hours already and I just can't seem to find this... I'm not that great at javascripts... Thanks a lot! Please advise me: I've successfully called a variety of functions that have no parameter value such as: function expand() //expand() in this line is merely an example But I'm unsuccessful calling a function with a paramter value such as: function expand(id) Here is the the call line: document.addEventListener("DOMContentLoaded", expand(id) , false); Here is the Function: function expand(id) { for (var i = 1; i<=10; i++) { if (document.getElementById('smenu'+i)) { document.getElementById('smenu'+i).style.display='none'; } } if (id) { id.style.display='block'; } } Hi, I have a search box he http://www.michael-williams.com.au/index.html I am using the below Java Script and form code to pass the entered value to search.html: <script type="text/javascript"> function searchVerify() { if(document.search.qt.value=="Enter keywords...") document.search.qt.value="";return true;} </script> <form id="search" method="get" action="search.html" onsubmit="return searchVerify()"> <p><input type="hidden" name="col" value="eu" ID="Hidden1"/><input type="hidden" name="style" value="nonpbs" ID="Hidden2"/><input type="hidden" name="nh" value="50" ID="Hidden3"/></p> <p style="float:left;"><label for="Search">Search:</label><input id="Text1" name="qt" type="text" value="Enter keywords..." class="textfield" onfocus="this.value=''" /><input type="submit" value="Go" class="button" ID="Submit1" NAME="Submit1"/></p> </form> I want to know how I can pass the entered value into the google search in the iframe on search.html. Can anyone help with this issue? Thanks. Hey guys, i have a question about my array. I have an array called numberarray with 20 elements and i want it to be accepted into a function as a parameter? But i only want the first 10 to be accepted. Does anyone know exactly how i would go about doing this in my function?
I have the following HTML code in main.html: Quote: ............. ............. <tr align="right"> <td width="50%"> ... ... ... </td> <td width="50%"> <iframe src="../createproject.html width="100%" height="400pt" frameborder="0" scrolling="no"> </iframe> </td> </tr> ........... ........... and createproject.html: Quote: <html> <head> <link rel="stylesheet" type="text/css" href="../user.css" /> <script type="text/javascript" src="../projects.js"></script> <head> <body onload="return capture_profile()"> <div align="right" class="data-font"> <form action="/cgi-bin/createproj.cgi" method="POST"> <fieldset> ....... ....... ....... </fieldset> </form><br/> </div> </body> </html> I'd like capture with capture_profile() function in createproject.html a value into main.html page. How can I solve this problem with javascript? 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> window.onload = function(){h = parseInt(document.getElementById( "div1" ).style.height);} var t; function addHeight(openAccordionID){ clearInterval(t); document.getElementById(openAccordionID).style.height = h+"px"; h+=1; t = setInterval("addHeight('"+openAccordionID+"')",10); for(var x=1; x<h; x++) if(h%(x*100)==0){clearInterval(t);} } </script> </head> <body> <div id="div1" onclick="addHeight(this.id)" style="width: 200px; height: 20px; background-color: yellow;">Increase Height</div> </body> </html> How can I still use the parameter "openAccordionID" in the blue-highlighted part? I tried, but it failed. |