JavaScript - How Do I Generate A Url From Variables
I am building a search function for a sermon blog on squarespace. The format url for category search is www.mysite.org/blog?category=... I have drop down menus and a datepicker but need to figure out how to get java to build the url and redirect to it. The output url should look like http://www.mysite.org/sermons?catego...+mybook+mydate. Any help would be greatly appreciated. Here is my java so far.
Code: function search() { var myRootSite = 'www.mysite.org/sermons?category='; var myNewTitle = document.getElementById('myTextField').value; var mySpeaker = document.getElementById('mySpeaker').value; var myService = document.getElementById('myService').value; var mySeries = document.getElementById('mySeries').value; var myBook = document.getElementById('myBook').value; var myDate = document.getElementById('myDate').value; if (myNewTitle == 0 && mySpeaker == 0 && myService == 0 && mySeries == 0 && myBook == 0 && myDate == 0) { alert('Please enter some search criteria'); return; } var title = document.getElementById('title'); title.innerHTML = mySpeaker; } Similar TutorialsHi, I am trying to develop a quiz system.Here is a simplified version of my code with lots of modifications made mainly for easier comprehension. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <script type="text/javascript"> var count=3; var questions = new Array(3); for (var i = 1; i <=count; i++) { questions[i] = "Question "+String(i); } </script> <script type="text/javascript"> /* Global "swap" holder Use value, null, if no layer initially visible */ var currlayerId = "question1"; function toglayer(id) { if(currlayerId) setDisplay(currlayerId, "none"); if(id)setDisplay(id, "block"); currlayerId = id; } function setDisplay(id,value) { var elm = document.getElementById(id); elm.style.display = value; } </script> <style type="text/css" media="screen, print, projection"> .text { display:none; } </style> </head> <body> <li><a href="#" onclick="toglayer('question1');return false;">Q.1</a></li> <li><a href="#" onclick="toglayer('question2');return false;">Q.2</a></li> <li><a href="#" onclick="toglayer('question3');return false;">Q.3</a></li> <div id="question1" class="text"> <script>document.write(questions[1]);</script> <br> </div> <div id="question2" class="text"> <script>document.write(questions[2]);</script> </div> <div id="question3" class="text"> <script>document.write(questions[3]);</script> </div> <script>toglayer('question1');</script> </body> </html> When you will run the code,you will find three links Q.1 Q.2 Q.3 These links are basically due to the following code Code: <li><a href="#" onclick="toglayer('question1');return false;">Q.1</a></li> <li><a href="#" onclick="toglayer('question2');return false;">Q.2</a></li> <li><a href="#" onclick="toglayer('question3');return false;">Q.3</a></li> When you click on any of the links,you will see the question associated with it.This is because of the following code Code: <div id="question1" class="text"> <script>document.write(questions[1]);</script> <br> </div> <div id="question2" class="text"> <script>document.write(questions[2]);</script> </div> <div id="question3" class="text"> <script>document.write(questions[3]);</script> </div> -------------------------------------------------------------------------------------- Now,here's the question,how do I put the div layers and their links in a loop.That is,I want it to be something like this Code: (for var i=1;i<=count;i++) { <li><a href="#" onclick="toglayer('question[i]');return false;">Q.[i]</a></li> } Code: (for var i=1;i<=count;i++) { <div id="question[i]" class="text"> <script>document.write(questions[i]);</script> <br> </div> } The reason why I ask this is,is because the number of questions in the quiz depends on the value of the javascript variable "count".Therefore,if the value of count is 5,the number of questions would be 5,if it is 6 the number of questions will be 6,etc. Thanks Hemant Hello, I'm a complete javascript beginner so sorry if I'm just being stupid I wanted to know if it's possible for me to add a picture (as in a .png file) to a page by clicking on something which would then make an image appear on the screen (which I would then want to be able to drag and move but I made a different thread for that question) I hope this explanation made sense Thank you for your time Hi, I am developing a html ordering system that does not use a database but sends the data via email. To differentiate between two orders I would like to generate and add an unique identifier to the email. One approach I have seen is using data object to generate an unique id: Code: function uniqid() { var newDate = new Date; return newDate.getTime(); } This is not guaranteed to be unique as two people can send their request at the exact same time. One question pops up, the data being generated, is this local or utc time? Also, the number being generated in this situation is quite big and not so easy to differentiate two orders for a human. Ideally I would like to generate a global sequence starting at 1 and incrementing by one for each user that clicks on the order button regardless of timing, timezone etc. Is this possible given the constraints given at the start of the post? Any suggestions are welcome. ok so heres where I stand, I don't know too much about javascript. Just enough to get me by. I am a PHP developer, I know how to do this in PHP but the client insists on doing it through javascript. Basically there are 3 different form values that determine the Premium Death Benefit Ratio. This is the formula the client wants: Premium to Death Benefit Ratio % (Created by formula = Annual (Level) Premium Amount (Divided by) Death Benefit Amount (equals a percentage) That percentage multiplied by Life Expectancy The 3 form values in the formula would be Annual Premium Amount (fypremium), Death Benefit Amount (dbp), Life Expectancy (average_le) I was messing around with javascript trying to figure it out and I have gotten no where since I am not used to writing formulas in JS. Anyways here is what I have so far: Code: function calculateLE(inputFieldId1, inputFieldId2, inputFieldId3, outputFieldId){ var DBR; var input = document.getElementById(inputFieldId).value; APA = document.getElementById(fypremium).value; DBA = document.getElementById(dbp).value; LE = document.getElementById(average_le).value; formula = document.getElementById(fypremium).value / document.getElementById(dbp).value = formula3; formula2 = document.getElementById(average_le).value * formula3; if { APA = "" } { document.getElementById(outputFieldId).value = "Error getting Annual Premium Amount"; } else if { DBA = "" } { document.getElementById(outputFieldId).value = "Error getting Death Benefit Amount"; } else if { LE = "" } { document.getElementById(outputFieldId).value = "Error getting Life Expectancy"; } else { document.getElementById(outputFieldId).value = formula3; } } Now I honestly have no clue if I am on the right track but what i've found on the net hasnt really pointed me in the right direction Here is the form values. Code: <input type="text" name="fypremium" id="fypremium" onblur="calculateLE('fypremium', 'dbp', 'average_le', 'premium_dbr')"> <input type="text" name="dbp" id="dbp" onblur="calculateLE('fypremium', 'dbp', 'average_le', 'premium_dbr')"> <input type="text" name="average_le" id="average_le" onblur="calculateLE('fypremium', 'dbp', 'average_le', 'premium_dbr')"> In a nut shell the values for the 3 inputs stated above will determine premium_dbr's value. fypremium / dbp = percentage; average_le * percentage = DBR (death benefit ratio); If someone could point me in the right direction to finishing this id be very greatful. Hi All, i want to achieve an effect like the following, please help 1. i want to get the current time, possibility no from client computer ( sometimes their time is wrong)? i dont know whether can achieve but if cannot, then never mind, just get from client computer. 2. for example now is 1:25 am, i want to generate dynamically every half an hour timing from 2 am(round up) till for example 11 am something like <select> <option>2:00</option> <option>2:30</option> ................ <option>11:00</option> </select> for me this is a bit complicated, anybody can help me? <option>3:00</option> Hello, I'm looking to create a web form with various text field to get input from users. Upon enter data to each field, users should have option to genenrate another text field underneath (i.e. a sub criteria of the above field). This is what i have so far, but i cannot get each button to generate the textfield right underneath. Here's my code: <html> <head> <title>test</title> <script> var maxFieldWidth = "500"; function addRow(element, indentFlag) { var elementClassName = element.className; // this is the class name of the button that was clicked var fieldNumber = elementClassName.substr(3, elementClassName.length); // current textfield width, take off the px on the end var fieldWidth = document.getElementById("textfield" + fieldNumber).style.width; fieldWidth = fieldWidth.substr(0, fieldWidth.indexOf("px")); // get the new field number (incremented) var newFieldNumber = ++fieldNumber; // get new field width in case we are indenting var newFieldWidth = fieldWidth; if(indentFlag) newFieldWidth = fieldWidth - (newFieldNumber * 10); var rowContainer = element.parentNode; // get the surrounding div so we can add new elements // create text field var textfield = document.createElement("input"); textfield.type = "text"; textfield.setAttribute("value", "textfield " + newFieldNumber); textfield.id = "textfield" + newFieldNumber; textfield.setAttribute("style","width:" + newFieldWidth + "px; margin-left: " + (maxFieldWidth - newFieldWidth)); // create buttons var button1 = document.createElement("input"); button1.type = "button"; button1.setAttribute("value", "++"); button1.setAttribute("onclick", "addRow(this, false)"); button1.className = "row" + newFieldNumber; var button2 = document.createElement("input"); button2.type = "button"; button2.setAttribute("value", "+"); button2.setAttribute("onclick", "addRow(this, true)"); button2.className = "row" + newFieldNumber; var button3 = document.createElement("input"); button3.type = "button"; button3.setAttribute("value", "-"); button3.className = "row" + newFieldNumber; // add elements to page rowContainer.appendChild(document.createElement("BR")); // add line break rowContainer.appendChild(textfield); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button1); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button2); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button3); } </script> </head> <body> <div id="main-container"> <div> <input type="text" id="textfield1" value="textfield 1" style="width:500px;" /> <input type="button" class="row1" value="++" onclick="addRow(this, false)"> <input type="button" class="row1" value="+" onclick="addRow(this, true)"> <input type="button" class="row1" value="-"> </div> </div> </body> </html> I wrote a java tool for scanning Js code and generating API documentation automatically. Jsdocx Project Website: http://jsdocx.sourceforge.net/ A online example document: http://jsdocx.sourceforge.net/exampl...ocx/index.html If you find bugs or have suggests, contact with me. Hello HTML CODE TUTORIAL support, I am aryan. A student of engg. I want simple help in following code : It is simple 4 You and difficult 4 Me :unsu ================================================ <html> <head></head> <title>Mad </title> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>MAD</title> <script language="javascript" type="text/javascript"> function session() { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var str = ''; for (var i=0; i<10; i++) { var b = Math.floor(Math.random() * chars.length); str += chars.substring(b,b+1); } document.frm.un.value = str; document.frm.s.value = str; document.frm.capt.src =" Free games - MAD.com init?w=120&h=40&f=png&s="+ str; document.getElementById("c").focus(); } </script> </head> <body> <form action='http://mad.com/ register' method='post' id='cI' enctype='text/plain'><p><input name='s' id='s' value='GENERATED 10 CHARACTERS HERE'' type='hidden'><p><input name='did' id='did' value='NEHA' type='hidden'><p><input name='pid' id='pid' value='twinkle' type='hidden'><p><input name='cid' id='cid' value='twinkle' type='hidden'><p><input name='l' id='l' value='en' type='hidden'> <p> <b>USERNAME</b><br> <input name='un' id='un' value='aliya_loves7' ><p><b>PASSWORD</b><br> <input name='pw' id='pw' value='Iaminhell8*'></p><p> <img src='http://mad.com/init? w=120&h=40&f=png&s=GENERATED 10 CHARACTERS HERE'></p><p> captcha <br><input name='c' id='c'><br><br><input name='send' value=' CREATE ' type='submit'></ form></font> </head> ================================================== In this code i wrote code in italic font. Which is modified by me And i want to know it is wrong or right ? I want to know exact what is wrong here. I tried many times but getting error. And i also want to know When i click on CREATE button, <img src='http://mad.com/init? w=120&h=40&f=png&s="GENERATED 10 CHARACTERS HERE> This value want to change automatically for next session But dont open next page i want to change this in that page likes Refresh Captcha when i press CREATE button One more thing I Have Four input Value ABHI,AKKI,SIMRAN,PRINCE I want to replace this value into NEHA input value. [You can see in code] I also want to change this value when Img src refreshed Please Help me Hi, I have a problem. please help me in this regard. I have a combobox which contain numeric values from 1-7. i want to generate a table with 2 rows and 4 columns through javascript. Means when a user select numeric value like '3' from a combo box then a page generates '3' tables without refreshing a page. And if a user selects '4' from a combobox then a script generates 4 tables with 2 rows and 4 columns and so on. kindly guide me that how can i mkae this javascript. plz help I have a script where I move randomly users from one multiple selectfield to another and that part works perfectly, but... When I want to submit the form I don't get any users passed along, course they are not "selected". I have then read around on the net and I need to create an elemet with a hidden input field where all the randomly selected users is inserted to with comma separation, but dont know how?!?! This is what I got: Code: function randomusers(){ var given = 3, used = {}, randnum, opts = $('#select1 option'), olen = opts.length; function ran() { // generate a unique random number randnum = Math.floor(Math.random() * olen); return used['u'+randnum] ? ran() : randnum; } for (var i = 0; i < given; i++) { // get the correct quantity of randoms used['u'+ran()] = true; } opts.filter(function(index) { // remove all options that are not one of the randoms return !!used['u'+index]; }).appendTo('#select2'); } I have tryied to insert this: appendTo('#select2' + '<input type="hidden" name="test[]" value="" />'); but that didn't seem right... Please help :-) Hey All, So to start out, this is my first post on CodingForums! I've only recently started learning web development so I figured it would be a good idea to get involved with some active forums. I am trying to open a random page in a frame, but I am trying to call the Javascript to do so in another frame. I currently have an html page with a frameset which has two frames. One of the frames is a toolbar that sits at the top of the page and it has an image that acts as button. When the user clicks on this image, the bottom frame generates a random page from an array of links I have hardcoded into the Javascript. The bottom frame is just set to google.com as a default because I couldn't really think of anything to put in an html file there. The problem I'm having is when I click on the image to open a random page in the bottom frame, nothing happens. The code for all the files are below. Home.html Code: <head> </head> <frameset rows='44,*' cols="*" frameborder='no'> <frame name="toolbar" noresize="noresize" src="toolbar.htm" marginwidth="5px" marginheight="10px" scrolling="no"> <frame name="main" noresize="noresize" src="http://www.google.com" marginwidth="5px" marginheight="5px" scrolling="auto" > </frameset><noframes></noframes> <body> </body> </html> The code for the frame, toolbar.htm: Code: <head> <title></title> <script type="text/JavaScript" src="random.js"></script> </head> <body> <div id="wrapper"> <div id="toolbar"> <a href="javascript:getaPage()"><img src="Images/nextpage.png" align="right" /></a> </div> </div> </body> </html> And finally the Javascript, random.js: Code: function get_random() { var ranNum= Math.floor(Math.random()*3); return ranNum; } function getaPage() { var randomPage=get_random(); var page=new Array(3) Page[0]="http://www.google.com"; Page[1]="http://www.yahoo.com"; Page[2]="http://www.myspace.com"; top.main.location.href=page[randomPage]; } And as a follow-up question, how difficult would it be to set up this entire random page generating script via php? I'm learning php so I can eventually set up a database of urls in mysql and have tags associated with each url. Thanks in advance! I would like to remove some hosting imposed google ads on my phpbb board. Currently I accomplish this by deleting via javascript all the banners divs when the page is loaded. But unfortunately in that way advertisements are quickly displayed before disappearing. Now I am thinking about a different (neater) approach to my problem: maybe I might write some javascript code which interferes with the one injected by google thus generating the inability to show those annoying divs... Any idea? As a homework assignment, we are being asked to generate a table of images with at least 2 rows and 3 columns from an external javascript function. I've been trying to find some kind of javascript reference for this and I can't. I don't want someone to do it for me, but if I could get a basic example that would be great.
Hey guys I'm trying to figure out the best/easiest/fastest way to accomplish this task: I have a csv file I need to generate an HTML item description based on the infomation in this csv Here is an example: ITEM NAME, ITEM TITLE, MANUFACTURE, CONDITION, LAST PHOTO LINK, I would then need the script to generate the HTML markup AND I will also need the script to determine if the last photo in the list is photo "c" and then create the links for photos a-c ie: <b>ITEM NAME<b><br> <i>ITEM TITLE</i><br> <img src="photoa.jpg"><img src="photob.jpg"><img src="photoc"><br><br> ect.... I'm sure there is a good way to do this I'm just not sure which language will be the easiest to do it in. If there is a way to use java I am most familiar with java. I would also like the script to export the data in a csv file as well if possible. Thanks for any advice guys! Please if you have any reference links post them! i have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads. var random = Math.floor(Math.random()*40 + 1) //sets variables for random numbers to generate var random2 = Math.floor(Math.random()*40 + 1) var random3 = Math.floor(Math.random()*40 + 1) var random4 = Math.floor(Math.random()*40 + 1) var random5 = Math.floor(Math.random()*40 + 1) var random6 = Math.floor(Math.random()*40 + 1) //create table function makeTable(lotto) document.getElementById("tableSpan").innerHTML = '<table border="1" id="lotto">'; var caption=document.getElementById('lotto').createCaption(); caption.innerHTML="JavaScript Random Numbers"; var x=document.getElementById('lotto').insertRow(0); var cell1=x.insertCell(0); var cell2=x.insertCell(1); var cell3=x.insertCell(2); var cell4=x.insertCell(3); var cell5=x.insertCell(4); var cell6=x.insertCell(5); cell1.innerHTML='<td class = "normal">'+ random +'</td>'; cell2.innerHTML='<td class = "normal">'+ random2 +'</td>'; cell3.innerHTML='<td class = "normal">'+ random3 +'</td>'; cell4.innerHTML='<td class = "normal">'+ random4 +'</td>'; cell5.innerHTML='<td class = "normal">'+ random5 +'</td>'; cell6.innerHTML='<td class = "red">'+ random6 +'</td>'; } heres the HTML file: <body onload="makeTable('lotto');"> <div id="container"> <div id="header"> <h1>Welcome</h1> </div> <div id="content"> <span id="tableSpan"></span> <input type="button" value="Re-generate Numbers" onclick="makeTable('lotto');" /> </div> { Can someone please help me generate a series of 13 digit numbers and output them to a text file. I'm really desperate here. Thanks guys. I've done a bit of searching and I can't find the answer to my question. I'm working on a website for my business. I have some basic knowledge of coding but I'm mostly a code cobbler. I find various pieces and put it together and hope it works so take it easy on me. I have some code to display products on my site. It works fine. We just have a lot of products and for me to add each one by hand was getting ridiculous. I finally had the bright idea to use Javascript to generate the code for me and then copy it back into my actual HTML page. Last night I wrote the code below. It works perfectly except I have to constantly "View Source" in order to get the code. I was hoping to cut down on a step or two and have the code go into a TextArea. From there I can just select it and copy it into the HTML file. It should make things a little quicker and most importantly easier. Maybe after that I'll try to figure out how to write function to select everything in the TextArea and copy it to my clipboard. That would make things even faster. Any help? 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=iso-8859-1" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> function calc (form) { var images = form.images.value; var imagesArray = images.split("\n"); var linebreak = "<br />"; var i=0; var j=0; var a=0; while(i < imagesArray.length) { if(j==0) { document.write (" <!-- -------------------------------------------- -->\n"); document.write (" <div id=\"cols3-top\"></div>\n"); document.write (" <div id=\"cols3\" class=\"box\">\n"); } a++; if(j/2!=1) { if(a==imagesArray.length) { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); break; } else { document.write ("\n <!-- ---------------- -->\n"); document.write (" <div class=\"col\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); i++; j++; } } else { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); i++; j=0; } } document.close(); } </script> </head> <body> <div style="width:960px; margin:0 auto;"> <form name="myform" method="get" action=""> <textarea label="Image Names:"name="images" cols="30" rows="15" onclick="this.value=''" ></textarea> <p> <label> <input type="button" name="calculate" value="Calculate" onClick="calc(this.form)"/> </label> </p> </form> </div> </body> </html> I pulled this code from Google's example section to make markers on a v3 Google Maps API (I have added my own lat/long points and corresponding event listeners, of course, but this is still the spirit of the code):
Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; function initialize() { var map_center = new google.maps.LatLng(39.2,-84.479381); var store1 = new google.maps.LatLng(39.112456,-84.574779); var store2 = new google.maps.LatLng(39.314153,-84.261379); var store3 = new google.maps.LatLng(39.197099,-84.667579); var store4 = new google.maps.LatLng(39.16836,-84.479381); var myOptions = { zoom: 10, center: map_center, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var marker1 = new google.maps.Marker({ position: store1, map: map, title:"Store 1" }); var marker2 = new google.maps.Marker({ position: store2, map: map, title:"Store 2" }); var marker3 = new google.maps.Marker({ position: store3, map: map, title:"Store 3" }); var marker4 = new google.maps.Marker({ position: store4, map: map, title:"Store 4" }); google.maps.event.addListener(marker1, 'click', function() { map.set_center(store1); map.set_zoom(16); }); google.maps.event.addListener(marker2, 'click', function() { map.set_center(store2); map.set_zoom(16); }); google.maps.event.addListener(marker3, 'click', function() { map.set_center(store3); map.set_zoom(16); }); google.maps.event.addListener(marker4, 'click', function() { map.set_center(store4); map.set_zoom(16); }); } </script> This works without fail, but when I try to use a javascript array to hold my values and loop my way through the marker creation like so: Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; function initialize() { var map_center = new google.maps.LatLng(39.2,-84.479381); var store_locations = new Array(); var temporary_stuff = new Array(); store_locations[0] = "39.112456,-84.574779"; store_locations[1] = "39.314153,-84.261379"; store_locations[2] = "39.197099,-84.667579"; store_locations[3] = "39.16836,-84.479381"; var myOptions = { zoom: 10, center: map_center, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); for(i=0;i<store_locations.length;i++){ var marker_string = "position: "+new google.maps.LatLng(store_locations[i])+", map: map, title:\"Store "+(i+1)+"\";"; temporary_stuff[i] = new google.maps.Marker(marker_string); } var markers = new Array(); for(i=0;i<temporary_stuff.length;i++){ var the_marker = "position: temporary_stuff[" + i + "], map: map, title:\"Store " + (i+1) + "\";"; markers[i]= new google.maps.Marker(the_marker); } } </script> I get a blank map. Here's a link to the test file: http://rowsdower.freehostia.com/map_test.php It's not throwing up any errors in Firefox's developer or in IE but there it sits, a blank map. I'm sure this isn't clean or optimized code, but it looks correct to me. I've color-coded the code above to show what "for" loops are being used to try to replace which code. Hopefully that makes this more sensible. I haven't even tried to add the listeners yet since I can't get the markers to appear. Can anyone tell me why this isn't working or point me in a more productive direction? Is there a better way already out there that I haven't noticed? |