JavaScript - Calling Function Within For Loop
Hi Everyone,
I am not able to figure out why the function "changeDiv(the_div,the_change)" is not called from the for loop in the function displayUsers(keeper)that I generated. The displayUsers is written to get rid of excess code in the function display(keeper). Can someone, please point out what the mistake is? Code: function changeDiv(the_div,the_change) { var the_style = getStyleObject(the_div); if (the_style != false) { the_style.display = the_change; } } function getStyleObject(objectId) { if (document.getElementById && document.getElementById(objectId)) { return document.getElementById(objectId).style; } else if (document.all && document.all(objectId)) { return document.all(objectId).style; } else { return false; } } //Shows input information for # of users selected function displayUsers(keeper) { var display=keeper; var i,user; for(i=1;i<= display;i++) { user="user"+i; changeDiv('user','block'); } } /*function display(keeper) { if (keeper == 1) { changeDiv('user1', 'block'); changeDiv('user2', 'none'); changeDiv('user3', 'none'); changeDiv('user4', 'none'); changeDiv('user5', 'none'); changeDiv('user6', 'none'); changeDiv('user7', 'none'); changeDiv('user8', 'none'); changeDiv('user9', 'none'); changeDiv('user10','none'); } else if (keeper == 2) ... ... ... else { changeDiv('user1', 'none'); changeDiv('user2', 'none'); changeDiv('user3', 'none'); changeDiv('user4', 'none'); changeDiv('user5', 'none'); changeDiv('user6', 'none'); changeDiv('user7', 'none'); changeDiv('user8', 'none'); changeDiv('user9', 'none'); changeDiv('user10','none'); } }// end function display(keeper)*/ Similar TutorialsOk, I'm nearly pulling my hair out with this one. I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together. What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array. What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created. Here is the test object: Code: test = [ { "name" : "Menu 1", "url" : "menu1.html", "submenu" : [ { "name" : "menu 1 subitem 1", "url" : "menu1subitem1.html" }, { "name" : "menu 1 subitem 2", "url" : "menu1subitem2.html" } ] }, { "name" : "Menu 2", "url" : "menu2.html", "submenu" : [ { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" }, { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" } ] }, { "name" : "Menu 3", "url" : "menu3.html", "submenu" : [ { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" }, { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" } ] } ]; Here is the recursive function: Code: function buildMenuHTML(menuData,level) { var ul; if (level == 1) { ul = "<ul id='menu'>"; } else { ul = "<ul class='level" + level + "'>"; } for (i = 0; i < menuData.length; i++) { menuItemData = menuData[i]; ul += "<li>"; ul += "<a href='" + menuItemData.url + "'>" + menuItemData.name + "</a>"; if (typeof menuItemData.submenu != 'undefined') { ul += buildMenuHTML(menuItemData.submenu,level + 1); } ul += "</li>"; } ul += "</ul>"; return ul; } Here is how the function is called initially: Code: buildMenuHTML(test,1); This is it's return value (with indentation added for readability): Code: <ul id='menu'> <li><a href='menu1.html'>Menu 1</a> <ul class='level2'> <li><a href='menu1subitem1.html'>menu 1 subitem 1</a></li> <li><a href='menu1subitem2.html'>menu 1 subitem 2</a></li> </ul> </li> </ul> 'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking, but any help would be appreciated. <p> <script type="text/javascript">// <![CDATA[ var metrics = { "mm" : 1, "cm" : 10, "m" : 1000, "inch" : 25.4, "foot" : 304.8 }; function convert(num, dec){ var val = document.getElementById("fromVal").value; if(isNaN(val)){ return } function roundNumber(num, dec) { var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec); return result; } document.getElementById("toVal").value = val * metrics[document.getElementById("fromSystem").value]/ metrics[document.getElementById("toSystem").value]; } var interval = null; function watchChanges(){ interval == null ? setInterval("convert()", 500) : clearInterval(interval); } // ]]></script> </p> <table> <tbody> <tr> <td><input id="fromVal" style="width: 100px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="fromSystem" onchange="convert()"> <option value="mm">millimeters</option> <option selected="selected" value="cm">centimeters</option> <option value="m">meters</option> <option value="foot">feet</option> <option value="inch">inches</option> </select></td> </tr> <tr> <td colspan="1" align="center">=</td> </tr> <tr> <td><input id="toVal" style="width: 100px;" type="text" disabled="disabled" /><select id="toSystem" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">meters</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select></td> 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> <style type="text/css"> #status { background-color:#FF0; width: 300px; height: 150px; overflow:scroll; margin-top: 25px; } #money { position:absolute; left: 325px; top: 416px; } </style> <script type="text/javascript"> function Machine() { this.getCash = function() { var i = 0; var rand = 0; while (i < 2) { t = setTimeout("rand = Math.ceil(Math.random() * 4 )", 1000); alert(rand); i++; } clearTimeout(t); } } var soda = new Machine(); soda.getCash(); </script> </head> <body> <div style="margin-bottom:25px"> Soda Machine. <p>_________________</p> 1. Earn Money <br /> 2. Buy Soda </div> <table> <thead> <th>Soda</th> <th>Price</th> <th>Buy</th> </thead> <tbody> <tr> <td> Basic Fizz </td> <td> $5 </td> <td> <input type="button" id="b_fizz" value="Buy Basic Fizz" /> </td> </tr> <tr> <td> Advanced Fizz </td> <td> $11 </td> <td> <input type="button" id="a_fizz" value="Buy Advanced Fizz" /> </td> </tr> <tr> <td> The Good Stuff </td> <td> $17 </td> <td> <input type="button" id="cc_fizz" value="Buy Coca Cola" /> </td> </tr> </tbody> </table> <div id="status"> <p style="margin-top:0">Status Window: </p> </div> <input type="text" id="money" value="$0" disabled="disabled" /> <input type="button" id="earn" value="Earn Cash" /> </body> </html> Basically, what I'm trying to do is get a random number every second for 2 seconds automatically so that in the status window it says: "You earned $2" "You earned $3" ....etc. But my random number keeps showing up as 0. I know I'm probably overlooking something as far as closures...can someone please enlighten me? Check the javascript code tried this also..same result for everything I try: D: Code: function Machine() { this.rand = 0; this.r = function() { this.rand = Math.ceil(Math.random() * 4); } this.getCash = function() { var i = 0; while (i < 3) { t = setTimeout("this.r()", 1000); alert(this.rand); i++; } clearTimeout(t); } } var soda = new Machine(); soda.getCash(); How can I call a PHP Function inside a Javascript Function? This is what I have so far, but I don't think I'm doing it the right way. Any suggestions? PHP Code: <?php function phpQuery(){ $query = mysql_query("INSERT INTO mytable VALUES('','name','email')"); } ?> <script type="text/javascript"> function delayQueries() { timeoutID = window.setTimeout(doQueries, 2000); } function doQueries() { var runQuery = "<?php phpQuery(); ?>"; } </script> I'm hoping someone can help correct a small problem with this script, which is intended to highlight particular text strings. Background: The script is being used at a MediaWiki site, and is adapted from a working script from Wikipedia (highlightmyname.js). The original script highlights the logged-in user's username (represented by wgUserName). I've made a copy of the script, which you can see in full here, and adapted it to work on a pre-defined array of names, adding: Code: var Admin; var ArrayAdmins = ['Adam', 'Axiomist', 'Matt', 'Steve']; for (Admin in ArrayAdmins) I also replaced each instance of wgUserName with ArrayAdmins[Admin] The problem: is that, instead of highlighting all instances of every element in ArrayAdmins, only the last element listed ('Steve') is being used. So my question is, what change(s) need to be made to apply function highlightmyname to every element in ArrayAdmins? Any help would be hugely appreciated! Hi, I am working on a google map where you can show lines on the map by checking checkboxes. Lines are displayed according to their category attribute in the xml file. The function that picks up the checkbox click is like this: Code: function boxclick(box,category) { if (box.checked) { show(category); } else { hide(category); } Another part of the code assigns that category attribute to arrows, so that when a line of "x" category is displayed, the relevant arrows are displayed along with it, to indicate directionality. I also have a select list which displays the lines by looping through their array and using selectedIndex in a function called handleSelected2. But I can't get the arrows to display along with the lines from the select box. After trying many, many things, I figure that all I need to do is to call the show(category) function from inside the handleSelected2 function and it should all come together. So I came up with this: Code: function handleSelected2(opt,category) { for (var h = 0; h <gpolylines.length; h++) { gpolylines[h].hide(); } h = opt.selectedIndex - 1; if (h > -1) { gpolylines[h].show(); } for (var v=0; v<pts.length; v++) { show(category); } } which gets me lines, but no arrows. You can see it sort of working he http://www.xelawho.com/map/zonesarrowstest.htm I figure I've got to be close, because if I just tell it to show all the arrows (without going through the category filter) like this: Code: function handleSelected2(opt,category) { for (var h = 0; h <gpolylines.length; h++) { gpolylines[h].hide(); } var h = opt.selectedIndex - 1; if (h > -1) { gpolylines[h].show(); } for (var i=0; i<pts.length; i++) { pts[i].show(); } } then all the arrows show up, as you can see he http://www.xelawho.com/map/zonesarrowstest2.htm I'm not getting any error messages and I've tried pretty much everything I can think of... I've been tweaking this for days and it's driving me crazy. Does anybody else have any ideas? Thanks in advance. I would like to call a function within a function. Is this even possible?? When I do this I get "undefined" Here's my code: Code: <html> <head> <script type="text/javascript"> function product(a,b){ total = a*b; display(total); } function display(num){ return num; } </script> </head> <body> <h1>This text I do NOT want to be erased.</h1> <a href="http://google.com" target="_blank">Total: </a> <script type="text/javascript"> product(3,4); document.write(display()); </script> </body> </html> I know you can just return in the first function, "product()" but I would like to do something else in my second function "display()" then return a value. thanks I am in a class that is right now creating an online quiz that is also displays time. The part I am running into a wall right now is "Call the runClock() function every second, storing the ID of this timed-interval command in the clockId variable." I am unsure how to call it every second. Also, how would I call a function within a function? Here is my code so far: <link href="quiz.css" rel="stylesheet" type="text/css" /> <script src="functions.js" type="text/javascript"></script> <script type="text/javascript"> var seconds = 0 var clockID = function runClock() { clockID = seconds++; document.getElementById("quizclock").value = seconds; } function startClock() { return showQuiz; } </script> </head> I need to create a form button named Create Resume. When clicked this button should call a function that generates a new Web page displaying a resume based on the user input. I am supposed to use the document.write() method to populate a newly generated Web page with all of the XHTML elements, formatting and variable values needed to produce the desired output in Web (.htm) format. I was hoping to get some guidance on how to accomplish this final step on my project. Any help would be greatly appreciated! KM <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Web 115 Final Project</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <script type="text/javascript" src="projectjs.js"> </script> <hr align="center" width="60%" /> </br> <script type="text/javascript"> document.write("<span style=\"font-family:garamond; text-align:center;font-size: 30px;\"> <p><b>Build Your Resume</b></p><\/span>"); </script> <form name="resume" method="get"> <p><input type="text" value="Enter your full name" size="50"/> </p><p> <input type="text" value="Enter your address" size="150"/> </p><p> <input type="text" value="Enter your phone number" size="50"/> </p><p> <input type="text" value="Enter your e-mail address" size="50"/> </p> <script language = "Javascript"> function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("Invalid E-mail ID") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at) ==lstr){ alert("Invalid E-mail ID") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot) ==lstr){ alert("Invalid E-mail ID") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Invalid E-mail ID") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Invalid E-mail ID") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Invalid E-mail ID") return false } if (str.indexOf(" ")!=-1){ alert("Invalid E-mail ID") return false } return true } function ValidateForm(){ var emailID=document.resume if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter your Email ID") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } </script> <p> <textarea id="tarea" cols="75" rows="4">Enter your personal information </textarea></p><p> <textarea id="tarea" cols="75" rows="4">Enter your career objectives </textarea></p><p> <textarea id="tarea" cols="75" rows="4">Enter your educational background </textarea></p><p> <input type="text" value="Most recent employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Most recent employment experience</textarea> </p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <input type="text" value="Employment beginning and ending dates" size="50"/></p><p> <textarea id="tarea" cols="75" rows="4">Additional Employment Experience</textarea></p><p> <textarea id="tarea" cols="75" rows="4">Character References</textarea></p><p> <textarea id="tarea" cols="75" rows="4">Business References</textarea></p></br> <input type="button" name="push_button" value="Create Resume"/> </form> </body> </html> New here. The issue is this: I am trying to display two clocks. I used the javascript clock generator (http://rainbow.arch.scriptmania.com/...generator.html) to create both clocks. However, the same code to place in the html was given to call each clock; <script language="JavaScript">displayTime();</script>. Below is the code for both clocks. What can be changed so that each clock displays on my website? Clock 1: function timeSource(){ x=new Date(timeNow().getUTCFullYear(),timeNow().getUTCMonth(),timeNow().getUTCDate(),timeNow().getUTCHours (),timeNow().getUTCMinutes(),timeNow().getUTCSeconds()); x.setTime(x.getTime()+10800000); return x; } function timeNow(){ return new Date(); } function leadingZero(x){ return (x>9)?x:'0'+x; } function twelveHour(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } function displayOnTime(){ if(fr==0){ fr=1; document.write('<font size=1 face=verdana><b><span id="tP">'+eval(outputTime)+'</span></b></font>'); } document.getElementById('tP').innerHTML=eval(outputTime); setTimeout('displayOnTime()',1000); } function amPMsymbol(x){ return (x>11)?'pm':'am'; } function fixYear4(x){ return (x<500)?x+1900:x; } var dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var monthNames=new Array('January','February','March','April','May','June','July','August','September','October','Novem ber','December'); var fr=0; var outputTime1="dayNames[timeSource().getDay()]+' '+timeSource().getDate()+' '+monthNames[timeSource().getMonth()]+' '+fixYear4(timeSource().getYear())+' '+':'+':'+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(tim eSource().getSeconds())+' '+amPMsymbol(timeSource().getHours())"; Clock 2: function timeSource(){ x=new Date(timeNow().getUTCFullYear(),timeNow().getUTCMonth(),timeNow().getUTCDate(),timeNow().getUTCHours (),timeNow().getUTCMinutes(),timeNow().getUTCSeconds()); x.setTime(x.getTime()+daylightSaving()-18000000); return x; } function timeNow(){ return new Date(); } function daylightSaving(){ return ((timeNow().getTime()>findDay(0,2,3,2).getTime())&&(timeNow().getTime()<findDay(0,10,3,1).getTime()) )?3600000:0; } function findDay(d,m,h,p){ var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(timeNow().getUTCFullYear(),nm,1,h,0,0),dOff=0; if(p<0){ x.setTime(x.getTime()-86400000); } if(x.getDay()!=d){ dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d); if(p<0&&dOff>0){ week-=7; } if(p>0&&dOff<0){ week+=7; } x.setTime(x.getTime()+((dOff+week)*86400000)); } return x; } function leadingZero(x){ return (x>9)?x:'0'+x; } function twelveHour(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } function displayTime(){ if(fr==0){ fr=1; document.write('<font size=2 face=Arial><b><span id="tP">'+eval(outputTime)+'</span></b></font>'); } document.getElementById('tP').innerHTML=eval(outputTime); setTimeout('displayTime()',1000); } function amPMsymbol(x){ return (x>11)?'pm':'am'; } function fixYear4(x){ return (x<500)?x+1900:x; } var dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var monthNames=new Array('January','February','March','April','May','June','July','August','September','October','Novem ber','December'); var fr=0; var outputTime="dayNames[timeSource().getDay()]+' '+timeSource().getDate()+' '+monthNames[timeSource().getMonth()]+' '+fixYear4(timeSource().getYear())+' '+':'+':'+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(tim eSource().getSeconds())+' '+amPMsymbol(timeSource().getHours())"; I've done a lot of work only to be stuck here at this problem. someone please help: Using the today variable as the parameter value, call the showDateTime() function and store the value returned by the function in the thisDay field of the eventform Web form. what exactly is this asking me to do? would you provide examples please? thanks in advance!@ In here is an example of a frameset im currently working. i have this frameset: http://www.mediafire.com/?75dvswgvelw19a9 what i want is when i select radio button "YES" and click on the "create" button in form1 http://www.mediafire.com/?eld7a1rb21h799e it will pass the value to radio button "ON" in form 2 http://www.mediafire.com/?f0o060cdpyf06ya and will call the function of the radio button "ON" -shows the hidden textarea. And if i select radio button "NO" in form1 and click on "create" button, it will select radio button "OFF" in form 2. help plsssssssss Code: <form> <input type="button" value="Click!" id="001" /> </form> function one() { window.alert('Hello'); window.alert('World!'); } var varname=document.getElementById("001"); varname.onclick=one; I am not sure if the last line is this example is correct. Should it not be: varname.onclick=one(); Or is it ok to write it either way? Thanks. I would like to add some javascript code that used for mobile browser detection to redirect page to another page. I would like to add it to content editor web part in sharepoint. I think I need to add it to the source editor. I got the following javascript code from a website. (function(a,b){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris| kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo| up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1- 6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te| us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa| cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el (49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w| od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\- (20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( | \/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/| ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50| p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok (6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po (ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/| sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl (45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg \-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk (40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)| wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))window.location=b}) (navigator.userAgent||navigator.vendor|| window.opera,'http://www.mycustomizedmobilepage.html'); {/script} I also learned that I need to add this line of code to the page: _spBodyOnLoadFunctionNames.push("functionName"); to call the javascript so that there is some kind of time delay to make the page upload to work correclty with the code. My question is: I see this javascript start with function(a,b), I did't see actually a function name, how can I call this function by using _spBodyOnLoadFunctionNames.push Thanks -------------------------------------------------------------------------------- Hi, I would like to do something like this: Code: function searchLocations(count) { var found = false; var input = document.getElementById('autocomplete').value; var inp = input.toLowerCase(); var count = 0; for (var j = 0; j < gmarkers.length; j++) { gmarkers[j].hide(); var str=gmarkers[j].myname.toLowerCase(); var patt1=inp; if (str.match(patt1)) { found = true; gmarkers[j].show(); count++; } } if (count==1) myclick(j); if (count>1) centerZoom(); if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } on this page here, but the functions - myclick(j); and centerZoom(); aren't getting called. I tried it with switches here, but that only made things worse. I know the functions work because if I put them two } up, they get called, but that takes them out of the if statements. Those if (count...) statements have to be where they are so that "count" will get the right value. Any ideas? Hi. Firstly, i apologise for this being a google maps related question but the problem is a regular javascript question i believe, and it's really frustrating me. As i'm sure you're aware that with the maps you can click on a red 'marker' and make an info box pop up. I'm trying to do this with a text link outside of the map. My problem is calling that script via the text link. i really can't see what i'm doing wrong; my html link Code: <a href="javascript;" onmouseover="marker.openInfoWindowHtml();">test</a> and the javascript from the map Code: GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(); }); I'm sure it's something simple but i've been trying variations for hours and I can't get my head around it. Anyone with any ideas would be an absolute star. Cheers, Pat. var macs = { getMacAddress : function() { document.macaddressapplet.setSep( "-" ); document.write( "Mac Address = " + document.macaddressapplet.getMacAddress() ); } how do i call this function and display out in the website? this doesn't seems working.. <script type="text/javascript"> document.write(mac.getMacAddress()); </script> Anyone help? hi i have a sliding vertical menu in my page in the left side and in the right side i have a text say for eg: Home. So when i click on home, i need the left side vertical menu to slide and open and the home in the left side should get highlighted. How do i do this in javascript ???? Pls help!!!! Hi, The point is to have a PHP code on the same page as a javascript calling the PHP function. I am able to make this work when the PHP code is on an external file. But when all but XSL are on the same page, it won't do what it should. How to make this work? The PHP is correct as it is by its self. And so is the javascript as it is for calling other PHP code. The combination of these two in this case just won't work. PHP and Javascript: [CODE] <html ><head><title>Untitled 1</title></head> <body> <?php function dateToDayOfWeek($xmlDate, $useFormat = 'l') { $rd = 'Unknown'; if (count($xmlDate) == 1) { $element = $xmlDate[0]; if ($element instanceof DOMElement) { $rd = date($useFormat, strtotime($element->nodeValue)); } } return $rd; } function axasal(){ date_default_timezone_set('UTC'); $xslDoc = new DOMDocument(); $xslDoc->load("xslfile.xsl"); // Here comes the xsl file name. $xmlDoc = new DOMDocument(); $xmlDoc->load("http://free.worldweatheronline.com/feed/weather.ashx?q=milan,italy&format=xml&num_of_days=5&key=af8b2fc417222733111712"); $proc = new XSLTProcessor(); $proc->registerPHPFunctions('dateToDayOfWeek'); $proc->importStylesheet($xslDoc); echo $proc->transformToXML($xmlDoc); } ?> <script type="text/javascript"> function call_php(){ document.getElementById("place").innerHTML="<?php echo axasal(); ?>"; } </script> <form name = "form"> <input type = "button" name = "aaa" id = "aaa" value = "Click me" onclick = "call_php()" /> </form> <div id="place"></div> </body></html> [CODE] XSL: [CODE] <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlnshp="http://php.net/xsl"> <xsl:template match="data"> <html> <head><title></title></head> <body> <table> <tr> <xsl:apply-templates select="./weather" /> </tr> </table> </body> </html> </xsl:template> <xsl:template match="weather"> <td style="width: 97px"> <p><xsl:value-of select="php:function('dateToDayOfWeek', date)" /></p> <p><xsl:apply-templates select="./weatherIconUrl" /></p> </td> </xsl:template> <xsl:template match="weatherIconUrl"> <img> <xsl:attribute name="src"> <xsl:value-of select="." /> </xsl:attribute> </img> </xsl:template> </xsl:stylesheet> [CODE] The smiley face on the second line of the last code is ':' and 'p'. I know I have a thread about the sorting function I'm about to post, but this problem doesn't deal with the sorting itself, but rather the fact that a variable is not passing. The code below is the relevant part to an autosuggest feature. The variable that isn't being passed is "firstValidIndex". It is being set appropriately, but when it is used in "sortArray()", its value is 0. Code: // here we must check to see if where the string matched was at the beginning of a string inside this.aNames // firstValidIndex is the first index where the char is at the beginning of a string var firstValidIndex; loop1: for(var j in firstIndices) { loop2: for(var k in allOccurrences) { if(allOccurrences[k] == firstIndices[j]) { firstValidIndex = firstIndices[j]; aList.push(this.aNames[i]); ctr++; break loop1; break loop2; } } } function sortArray(a,b) { var lca = a.toLowerCase(); var lcb = b.toLowerCase(); var lco = str.toLowerCase(); var diff = lca.indexOf(lco,firstValidIndex) - lcb.indexOf(lco,firstValidIndex); // some debugging code here alert("Comparing "+lca+" with "+ lcb+"\nDiff:"+diff+"\nFirst Valid Index: "+firstValidIndex); if ( diff < 0 ) return -1; if ( diff > 0 ) return 1; return 0; } aList.sort(sortArray); |