JavaScript - Passing A Value In Dashcode - Querystring Or Getelementbyid?
hi,
Now that I have my list of Towns (using JQuery to connect to mySQL and show data in JSON format) I would like to click on a town and pass the town name so I can request it from querystring or getElementByID and then in a simple IF statement or whatever select the PHP page WHERE Town = Selected Town I hope someone can point me to a relevant tutorial? Similar Tutorialshi, I am trying to setup an iphone application in Dashcode using what I have he http://www.mypubspace.com/dashtest/order.html Result of expression 'ajaxDisplay' [null] is not an object which is on the following line: Code: ajaxDisplay.innerHTML = ajaxRequest.responseText; is there a way around this? thanks Hello! I am trying to implement some JS that redirects a user after selection from a drop down box. The redirection includes a querystring so I want to use base64 to encode that. The 'goto' code below works fine if I remove the reference to the encode64 function. However when I use the encode64 function it doesn't work. So I'm guessing I have something wrong with the base64 portion. Code: <script language="JavaScript"> var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; function encode64(input) { var output = new StringMaker(); var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4)); } return output.toString(); } function goto(form) { var index=form.drpAccount.selectedIndex if (form.drpAccount.options[index].value != "0") { location="/billing-test.php?q=" + encode64(form.drpAccount.options[index].value); } } </script> Hi, I'm just starting out with a few bits of javascript and have hit a problem. The story is this: I have a basic HTML page that I want to display using a different css file depending on the page that the request comes from. I though I'd do this by appending "?cs=a" or "?cs=b" depending on the calling page. My problems are occuring whilst trying to read the data in the URL (querystring?) The code below is meant to be a bit of a debugger sort of affair in that it should display the variables but for the life of me I can't get it to work. The problem is that none of the variables seem to be getting populated with data, therefore nothing is displayed on the page and no css file is loaded. I'm pretty sure its something relatively simple so would appreciate if an expert could cast their eye over what I have below and point out the error of my ways... Code: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%> <!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> <SCRIPT type="text/javascript"> var thequerystring = new String(Request.QueryString("cs")); if (thequerystring == "a") { cssfile = "css1.css"; } if (thequerystring == "b") { cssfile = "css2.css"; } document.write('<link href="'+cssfile+'" type="text/css" rel="stylesheet">'); </SCRIPT> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p><span class="texttype">hello</span></p> this should change the format of the text depending on the css file that was loaded... in theory!! <p> </p> <p>Here is a list of the variables and their values... <script type="text/javascript"> document.write('<b>Some variables...</b><br>'); document.write('cssfilename: '+cssfile+'<br>'); document.write('Querystring text: '+thequerystring+'<br>'); </script> </p> <a href="javascript: history.go(-1)">Back <-- </a> </body> </html> Many thanks in advance Dan Hello, i'm working on a 3 page survey. When hitting next, previous, or submit it passes the values of all the questions to the next page. I've got the whole thing working correcting except for one thing: When the box is "not" checked it passes no value. I'm needing it to have a value of "1" when checked and a value of "0" when not checked, and currently when its not checked and i pass the info it leaves it blank. I'd post the whole code to one of the pages but it's long , so i'll post the snipits of the code. Code: <script type="text/javascript"> /* <![CDATA[ */ function processQueryString() { var formData = location.search; formData = formData.substring(1, formData.length); while (formData.indexOf("+") != -1) { formData = formData.replace("+", " "); } formData = unescape(formData); var formArray = formData.split("&"); for (var i=0; i < formArray.length; ++i) { //document.writeln(formArray[i] + "<br />"); var sDataName = formArray[i].split("=") switch (sDataName[0]) { case ".lib_use": for (var j=0; j < document.getElementsByName(".lib_use").length; ++j) { if (document.getElementsByName(".lib_use").item(j).value == sDataName[1]) { document.getElementsByName(".lib_use").item(j).checked = true; //alert("lib_use set"); } } break; case ".lib_comp": if (sDataName[1] == 1) { document.getElementsByName(".lib_comp").checked = true; document.getElementsByName(".lib_comp").value= 1; } else { document.getElementsByName(".lib_comp").checked = false; document.getElementsByName(".lib_comp").value= 0; } break; default: alert("not caught = " + sDataName[0]); continue; } } } /* ]]> */ </script> <input type="checkbox" name=".lib_comp" id="lib_comp" value="1" /> The first case that i showed in my code is a radio button, and it passes correctly, i just wanted to show the "format" i was using in a working sense. The 2nd case is an example of the check boxes. Thanks for looking at this, and giving any suggestions you might have! Dear all, I'm passing the variables myTitle and myLink to form.php using javascript. This is the way I'm doing it: Code: <a href='form.php?title=" + myTitle +"&link="+myLink+">Click me</a> It's working great but sometimes myTitle and myLink contain the plus character (+). When this happens it's not passed. In the case of the title, it's just a problem of looks but in the case of the link, well, the link won't work without the character. As an example if the title is: Laptop + Accessories What is passed is: Laptop Accessories What can I do to pass also the plus character?? Thanks a lot!! Hi, I have what I assume started as a simple error and then trying to fix it I think I have made things so complicated I've become confused. I have two fields, a drop down list and a text field, when someone clicks on a value in a drop down list (I will show the results eventually but at the moment) I just want the result to echo in my getCategory.php and the same for the text field. Both php pages are currently being called. And at the moment contain $_REQUEST['category'] and $_REQUEST['ProductName'] respectively. Nothing is being echoed. I know the below code is wrong, but the more I try to correct it the worse it gets so I thought I would just leave it as is before I made it worse. Code: <script type="text/javascript"> function loadXMLDoc1(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> </head> <body> <label>Search by Category: </label> <select name="category" id="category" onchange='loadXMLDoc1("getCategory.php","txtHint","category")' class="input"> <option value="please select" selected"selected">Please Select</option> <option value="Clothes" name="Clothes" id="Clothes">Clothes</option> <option value="Bags" name="Bags" id="Bags">Bags</option> <option value="Hats" name="Hats" id="Hats">Hats</option> </select> <br /> <br /> <label>Search by name: </label> <input type="text" class="input" name="ProductName" id="ProductName" value="Search" size="30"/> <input type="button" value="Search" onclick="loadXMLDoc1('getProductName.php','txtHint', ProductName='(this.value)')" /> <br /> <br /> <div id="txtHint"></div> Hi, I've had problems in the past understanding this, however, after reading this tutorial, I understand. In some languages, like VB6, I notice the "byVal" and the "byRef" is specifically used. In javascript, I don't notice those specifics typed in functions. Is the "default" by value when using in a function to change a parameter? If it is, what is the syntax for using by reference, or is that ever used? My question arises from this notation taken from here: Quote: Note that it is the value that a has at the time that it is passed into the function that gets substituted into the argument and not the value that the original variable has at that point in the processing. It is the values in the parameters that the function uses and not the variables. This is called pass by value . In those languages where you can pass the actual variable into the function instead of just passing its value the method used to do so is called pass by reference . Had we been able to pass the variables into the function by reference rather than by value then the final value in b would have been -16 instead of -14. Here is the example (passing by value): Code: function myfunction(y, z) { a += y; b -= z; } var a = 0; var b = 10; var c = 3; var d = 4; var e = 2; myfunction(c, d); myfunction(d, e); myfunction(9, 2); myfunction(b, a); Results: myFunction(c, d); output: 0 + 3 = 3(y), 10 - 4 = 6(z) myFunction(d, e); output: 3 + 4 = 7(y), 6 - 2 = 4(z) myFunction(9, 2); output: 7 + 9 = 16(y), 4 - 2 = 2(z) myFunction(b, a); output: 2 + 16 = 18(y), 2 -16 = -14(z) Thanks! hi, In my code below, I cannot get the setting_id value as it falls outside of the loop. I have just tried to put in the getElementById function but it's not working?! I get the error: missing ) after formal parameters JavaScript from this: Code: function confirmqualification(ID) { to this: Code: function confirmqualification(document.getElementById('setting_id')) { HTML from this: Code: <input type="button" name="remove" id="remove" value="Remove" onClick="javascript:confirmqualification('<?php echo $row1['setting_id']?>')" /> to this: Code: <input type="button" name="remove" id="remove" value="Remove" onClick="javascript:confirmqualification()" /> hi quick question, i have 640 hidden html inputs like this but with different names. <input type="hidden" name="b1r1c1" value"some value"> now i want to use document.getElementById('b1r1c1).value = "whatever"; will that work eventhough there is no id on my hidden value. it will be in a hta by the way. thanks Hello smart people... perhaps someone can figure this one out. I hope it's not a PHP question. I have a form and need to populate FIELD2 with the result of FIELD1. Field one is a dynamic list from a database, where the value is an ID#, but the list shows the name. I want to populat FIELD2 with the name that is chosen, not the id (I can't get anything to work) Here is the code from the 2 fields: FIELD 1: Code: <select name = "" realname = "{#role#}" required="1" exclude = "-1" id = "roleselect"> <option value="-1" selected="selected">Choose</option> <option value = "{$roles[role].ID}" id="role{$roles[role].ID}">{$roles[role].name}</option> FIELD 2: Code: <input type="hidden" name="rolename" id="rolename" required="0" realname="rolename" /> Here is the javascript I tried to populate field 2 with the selected option of field 2: Code: function updaterole(){ document.getElementById("rolename").value =document.getElementById("role").value; I tried using name instead of value for field 1, but that didn't work either. The db just shows empty. thanks for any help! Hopefully some of you guys can help. I'm self taught in Javascript so only know little bits here and there (and don't even know if the thread title is labelled right for what I'm doing!) so help would be greatly appreciated. I'm trying to create 4 buttons on a page (buttons shown by "click here to view c1, c2" etc.) however after I've clicked one button and the content is showing below, the content from the next button clicked does not show (almost as if it is hidden underneath). I'm looking for a way of showing the content when the button is clicked, but hiding it once another button is clicked so other content is shown. Hopefully this is clear enough. All help, tips or advice will be appreciated. Thankyou. Code: <script type="text/javascript" language="JavaScript"><!-- function InsertContent(tid) { if(document.getElementById(tid).style.display == "none") { document.getElementById(tid).style.display = ""; } else { document.getElementById(tid).style.display = "none"; } } //--></script> <table width="100%" cellspacing="4" cellpadding="4" border="0" align="center"> <tbody> <tr> <td width="25%"><a href="javascript:InsertContent('c1');"> Click to see C1</a></td> <td width="25%"><a href="javascript:InsertContent('c2');"> Click to see C2</a></td> <td width="25%"><a href="javascript:InsertContent('c3');"> Click to see C3</a></td> <td width="25%"><a href="javascript:InsertContent('c4');"> Click to see C4</a></td> </tr> </tbody> </table> <hr /> <div style="display: none; border: 0px dashed black; background-color: white; color: black; font-weight: bold; padding: 5px; margin: 5px;" id="c1">CONTENT C1 </div> <div style="display: none; border: 0px dashed black; background-color: white; color: black; font-weight: bold; padding: 5px; margin: 5px;" id="c2">CONTENT C2 </div> <div style="display: none; border: 0px dashed black; background-color: white; color: black; font-weight: bold; padding: 5px; margin: 5px;" id="c3">CONTENT C3 </div> <div style="display: none; border: 0px dashed black; background-color: white; color: black; font-weight: bold; padding: 5px; margin: 5px;" id="c4">CONTENT C3 </div> I am using javascript for adding and removing rows from table as per user require ment like if we press ADDROW button it adds extra row to table and if we pressREMOVEROW it delets the last row.. Now i want to access the data from textbox like this.. var crpt = document.getElementById("itrtr2").value; //no. of rows for(var k=1;k<=crpt;k++) { qtyc = document.getElementById("txtRowc3"+k).value; unit_pricec = document.getElementById("txtRowc5"+k).value; alert('QTYC:'+qtyc+' UPC:'+unit_pricec); cttl = qtyc * unit_pricec; document.getElementById("txtRowc6"+k).value = cttl.toFixed(2); csbttl = csbttl + cttl; } document.getElementById("subttlC").value=csbttl.toFixed(2); it shows the value of textRowc3i in qtyc in alert box but also givs error document.getElementById("txtRowc3"+k) is null.. I tried for this but problem is not solved please help... Thank You... why is getElementById not working?? pls try it and tell me if you get a hit on document.getElementById("t1"); thanks Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Tester code</title> <script type="text/javascript"> console.log("sfsg"); var e = document.getElementById("t1"); var c = e.firstChild; console.log(c); </script> </head> <body> <table> <tr> <td id="t1"><img id="img1" src="SharkSq1.png">3</td> </tr> </table> </body> </html> hi, on my site he http://www.mypubspace.com/default.php I am requesting the rsCounty by Ajax, I am then trying to do the same to the page number value using getElementByID, and building up the querystring, but it's not working properly, on my countypubs.php page which is what I an requesting to get the counties I have added the function again to try and get the PAGE Code: <script language="javascript" type="text/javascript"> function countyFunction(){ var countyRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari countyRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ countyRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ countyRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server countyRequest.onreadystatechange = function(){ if(countyRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = countyRequest.responseText; } } var name = document.getElementById('name').value; //var rsCounty = document.getElementById('rsCounty').value; var page = document.getElementById('page').value; var queryString = "?name=" + name + "&rsCounty=" + rsCounty + "&page=" + page; //Add the following line countyRequest.open("GET", "http://www.mypubspace.com/countypubs.php" + queryString, true); countyRequest.send(null); } </script> <?php $dbhost = "xxx"; $dbuser = "xxx"; $dbpass = "xxx"; $dbname = "xxx"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); if ($msg <>"") { echo "<div class=\"ui-widget\"> <div style=\"padding: 0pt 0.7em;\" class=\"ui-state-error ui-corner-all\"> <p style=\"padding-top:18px;\"><span style=\"float: left; margin-right: 0.3em;\" class=\"ui-icon ui-icon-alert\"></span> <strong>Alert:</strong> $msg</p> </div> </div>"; } $county = $_GET["rsCounty"]; echo $county .'<br />'; $tableName="pubs"; $targetpage = "default.php"; $limit = 20; $query = "SELECT COUNT(*) as num FROM $tableName WHERE rsCounty = '$county'"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages['num']; $stages = 3; $page = mysql_escape_string($_REQUEST['page']); if( isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) ) { $page = (int) $_GET['page']; $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM $tableName WHERE rsCounty = '$county' ORDER BY rsPubName Asc LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<span class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a onClick='countyFunction();' id='page' value='$prev'>previous</a>"; }else{ $paginate.= "<span class='disabled'>previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a onClick='countyFunction();' id='page' value='$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>next</a>"; }else{ $paginate.= "<span class='disabled'>next</span>"; } $paginate.= "</span>"; } echo 'Pubs found: '.$total_pages; // pagination echo $paginate; ?> <div id="ajaxCountylist"> <div id="accordion"> <?php while($row = mysql_fetch_array($result)) { echo '<div><h3><a href="#">'.$row['rsPubName'].', '.$row['rsTown'].'</a></h3><div>'.$row['rsAddress'].'<br />'.$row['rsTown'].', '.$row['rsCounty'].'<br />'.$row['rsPostCode'].'<br /><br />Region: '.$row['Region'].'<br /><br />Telephone: '.$row['rsTel'].'<br /><br />'; echo '<button onclick="gohere(\'viewpub.php?PUBID='.$row['PUBID'].'\')" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">View Pub</span></button>'; echo '</div></div>'; } echo '<span style="float:right;">'.$paginate.'</span>'; ?> </div> </div> I have only applied teh function to the previous button and the first page numbers! None of my getElementById (or other) references produce anything but "undefined." This occurs in the latest versions of Fx, IE, Chrome, and Safari, so it must be something I am doing but not not seeing here. I have boiled it down to the following without success, and wonder whether there is some add on interaction. Fx 3.6.12 has the problem with this code: <code> <html> <head> <title>This is a test of getElementById</title> </head> <body> <div id="area" name="area_name">xxx</div> <script type="text/javascript"> var divs = document.getElementsByTagName('div'); var msg = ''; msg = 'Divs[0] contains ' + divs[0] + ' with width = ' + divs[0].width + "\n"; msg +='Test area width by id = ' + document.getElementById('area').width + "\n"; msg +='Test area width by name = ' + document.getElementsByName('area_name').width; alert(msg); </script> </body> </html> </code> Hi - Code: function EvalSound(soundobj) {// this passes the sound to be played to the java applet embedded in the html file and plays it. see ref: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm document.getElementById(soundobj).Play(); } I get a firebug error message 'getElementB...ay is not a function'. However, this error only occurs on my machine at work where I am running Firefox for U3 (updated to FF 3.5.5) - U3 is a SanDisc flash drive. When I run the same code on FF 3.5.5 from home there is no error. The code works in all other browsers I've tested (IE6, IE8, Chrome). The page is http://dermdudes.com/counter/keycounter.html Please provide feedback if the page does not work for you. Please help. Thanks, Jim I have some simple javascript code that works fine in chrome and safari, but not Ie8 Code: <head><script type="text/javascript"> function val2() { //var num = Number(document.getElementById('PdRows').value) alert (document.getElementById('PdRows').value) } </script></head> <form action="" method="post"> <select name="PD" id="PdRows" onchange="val2()"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </form> Why? And how do I correct? Hey guys, Thanks for taking the time to read my post. I am not new to programming or scripting, but I am completely new to javascript and web-based code. Hopefully you guys could help me understand what is going on and maybe help me figure out what I am trying to do. What I am trying to do: -There is an element that has a value <td class="flashField" onmouseover="clearAnswer()"> <div id="flashAnswer" onmouseover="clearAnswer()">answer string here</div> </td> -There is a text box that needs to have the answer above given to it <td class="flashField"> <input type="text" tabindex="1" onkeypress="clearAnswer()" name="q" maxlength="256" size="50"> </td> -There is a next button that needs to be executed <td align="right"> <input type="image" tabindex="2" alt="Next" src="http://website.com/images/next.gif"> </td> So what I am trying to do is create a script through Greasemonkey that will automatically do these things. I am starting small and trying to just get the value of flashAnswer to appear as an alert on the screen by using this code: var answer = document.getElementById('flashAnswer'); alert(answer); But the problem is it posts some weird value ([object XrayWrapper [object HTMLDivElement]]) that most definitely is not "answer string here" and is a bit above me at this point. Any ideas? Any help would be great guys! Thanks! -ellosiph Hi, quick question: Code: function x() { document.getElementById('myid').width += 200; } This works for "myid", but my document contains "myid1", "myid2", "myid3", and so forth. How can I alter the script to effect every instance of "myid" followed by a number? Hi, I asked this question in an earlier post where Dormilich asked me to post the code, which I did twice but for some reason it hasn't posted so I'll try with a new thread.... I am passing a variable to a function in a separate .js file using embedded HTML. I want to use the parameter in a getElementById but I can't get it to work. Here's my HTML: Code: <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT"> <!-- window.onload = function () { initSlideDownMenu("accordionactivity"); } //--> </SCRIPT> Here's my javascript function. When the first alert pops up I get 'accordionactivity', when the second one pops up I get '[object]' but when the third one pops up I get 'null'.The rest of the function then doesn't work properly either: Code: function initSlideDownMenu(slMenuName) { alert(slMenuName); alert(document.getElementById('accordionactivity')); alert(document.getElementById(slMenuName)); dhtmlgoodies_slmenuObj = document.getElementById(slMenuName); dhtmlgoodies_slmenuObj.style.visibility='visible'; var mainUl = dhtmlgoodies_slmenuObj.getElementsByTagName('UL')[0]; var mainMenuItem = mainUl.getElementsByTagName('LI')[0]; mainItemCounter = 1; while(mainMenuItem){ if(mainMenuItem.tagName=='LI'){ var aTag = mainMenuItem.getElementsByTagName('A')[0]; var subUl = mainMenuItem.getElementsByTagName('UL'); if(subUl.length>0){ mainMenuItem.id = 'mainMenuItem' + mainItemCounter; initSubItems(subUl[0],2); aTag.onclick = showSubMenu; mainItemCounter++; } } mainMenuItem = mainMenuItem.nextSibling; } if(location.search.indexOf('mainMenuItemToSlide')>=0){ var items = location.search.split('&'); for(var no=0;no<items.length;no++){ if(items[no].indexOf('mainMenuItemToSlide')>=0){ values = items[no].split('='); showSubMenu(false,document.getElementById('mainMenuItem' + values[1])); initMenuIdToExpand = false; } } }else if(expandFirstItemAutomatically>0){ if(document.getElementById('mainMenuItem' + expandFirstItemAutomatically)){ showSubMenu(false,document.getElementById('mainMenuItem' + expandFirstItemAutomatically)); initMenuIdToExpand = false; } } if(expandMenuItemByUrl) { var aTags = dhtmlgoodies_slmenuObj.getElementsByTagName('A'); for(var no=0;no<aTags.length;no++){ var hrefToCheckOn = aTags[no].href; if(location.href.indexOf(hrefToCheckOn)==0 && (location.href.length==hrefToCheckOn.length || location.href.indexOf('?')==hrefToCheckOn.length)){ initMenuIdToExpand = false; var obj = aTags[no].parentNode; while(obj && obj.id!=slMenuName){ if(obj.tagName=='LI'){ var subUl = obj.getElementsByTagName('UL'); if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true; if(subUl.length>0){ objectsToExpand.unshift(obj); } } obj = obj.parentNode; } showSubMenu(false,objectsToExpand[0]); break; } } } if(initMenuIdToExpand) { objectsToExpand = new Array(); var obj = document.getElementById(initMenuIdToExpand) while(obj && obj.id!=slMenuName){ if(obj.tagName=='LI'){ var subUl = obj.getElementsByTagName('UL'); if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true; if(subUl.length>0){ objectsToExpand.unshift(obj); } } obj = obj.parentNode; } showSubMenu(false,objectsToExpand[0]); } } Can you help me figure out what I'm doing wrong? Thank you! |