JavaScript - Onclick With More Than One Parameter
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 Similar TutorialsHi 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! This is a form to calculate a players age as of May 1st of each year. I need to send the result in a URL string to "http://ntsacom.homestead.com/TEST3.html?TEAM_ID=TS63464122&LOG_IN_ID=11111111&league_age=[FORM RESULT] Can anyone help. This to complete a roster app for our youth BASEBALL league. My JavaScript is very limited and the gentleman that was working on this has abandoned it after receiving pay for the project (lesson learned). I have enough knowledge to finish the project once we figure this one small piece out. Thank you for looking at this for me! Code: <p id="form"></p> <form id="get_birthday" name="get_birthday"> <select id="form_get_month" name="form_birth_month"> <option value="0">january</option> <option value="1">february</option> <option value="2">march</option> <option value="3">april</option> <option value="4">may</option> <option value="5">june</option> <option value="6">july</option> <option value="7">august</option> <option value="8">september</option> <option value="9">october</option> <option value="10">november</option> <option value="11">december</option> </select> <select id="form_birth_day" name="form_birth_day"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select id="form_get_year" name="form_birth_year"> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> </select> <input onclick="calculate_age();" type="button" value="submit " /> </form> <-------------$ I want this to pass as a URL parameter "onclick" of the above button --------------> <p id="baseball"> <script language="JavaScript"> <!-- hide script from old browsers --> function calculate_age() { var birth_year = window.document.get_birthday.form_birth_year.value; var birth_month = window.document.get_birthday.form_birth_month.value; var birth_day = window.document.get_birthday.form_birth_day.value; if (((birth_month == 3) || (birth_month ==5) || (birth_month==8) || (birth_month==10)) && (birth_day==31)) { alert("Please check that you entered a valid date") return; } if ((birth_month == 1) && (birth_day >28)) { alert("Please check that you entered a valid date") return; } //Create the date object for todays date var now = new Date(); //Extract the current year, var the_year = now.getFullYear(); // Calculate elegibility for sport var league_text = "" var paragraph = document.getElementById("baseball"); //Clear the contents of paragraph if the submit button has been clicked more than once . //the Firefox way if (paragraph.innerText = ""); else //The MSIE way if (paragraph.textContent = ""); var league_age = (the_year - birth_year) if (birth_month > 3) league_age --; if (league_age < 5 ) { league_text = "1" } if ((league_age > 5) && (league_age <12)) { league_text = "1" } else if ((league_age >12) && (league_age <16)) { league_text = "1" } else if ((league_age >15) && (league_age <19)) { league_text = "1" } else if (league_age > 18) { league_text = "1" } var output_text = document.createTextNode(league_text); var output_age = document.createTextNode(league_age); paragraph.appendChild(output_age); paragraph.appendChild(output_text); S.redirectTo("search-results?baseball=value1") } </script> I'm currently working on a project and I am doing a bunch of image switching. I'm having a problem with the following... I have seven medium image objects and one small one. One is at the top and the other 7 are below. When one of the 7 is clicked, it then becomes the one up top and the one up top then takes the place of the image clicked. This needs to be able to happen no matter which of the seven i click. Also when you click one of the seven it runs a script to change 9 other images in the center of the page. this isnt too important because i have it working already. What i have is, each of the seven images run their function that changes the 9 center images and then it runs another function. What i need is for that function to determine which company for example(shaws, lowes, target) the top image belongs to and replace the image that was clicked with the top one. But i also need to replace the NAME="" and ONCLICK="function()" with the proper ones for the original company up top. Please if you can understand what im trying to do let me know, if you need further clarification i can do so. i can draw a picture of what im trying to do or the layout if needed but i cant necessarily show anyone the project due to a non-disclosure. Is it possible disable an onclick after clicking it and then enable it from another onclick by id Code: <img id="one" href="images/homepage/sliders/bonus_button.jpg" style="position:relative; top:30px; left:50px; height:30px; width:70px; float:left;"> This code runs when it is clicked: Code: $("#one").click(function() { runEffectB(); return false; }); What I would like to happen is for either runEffectB() to not run if it was just run or to disable the #one.click once it has run. I am assuming I will be able to re-enable it from another onclick running a similar function. This is jquery and jquery ui if that helps. Any ideas much appreciated. 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) 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> 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! 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]; 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? 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 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. 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')} I 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 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. 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! 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?
|