JavaScript - [associative Array] How Would You Do That In Javascript?
Hi,
New to javascript here. I'm trying to do something that would be very easy to do in php, but is quite hard in javascrpit due to the lack of support of associative array. PHP Code: var myArray = new Array(); //a click event has been detected //var clickedElementId = get the clicked element id... myArray[clickedElementId ] = true; And if the element gets clicked again: PHP Code: if(isset(myArray[clickedElementId ])){ unset(myArray[clickedElementId ]); } I can use .push() to add clickedElementId as a value associated to a numeric key, but then how would you remove a specific element from the array? How would you approach such a typical algo in javascript? Regards, -jj. Similar TutorialsSomething like this: ['level1key':['level2key:'value']] That is the value itself is any object. Hi, I am trying to save information to a multidimensional associative array, when a use inputs data about booking a restaurant table. So basically if he user changes his/her mind and cancels but wants to retrieve that information again at the same time they can do so. So for example the information would be like: - Code: Table 1 Customer Name Time Seats Table 2 Customer Name Time Seats etc. Now what I want to know is how do I implement this as a multi-associative array and how do I retrieve the values. Hey, i am just trying to learn javascript and my friend gave me a little assignment to try and figure out. i am having trouble figuring it out and need some help. basically i just want to display the information in my associative array, into an html table. var NFC_east = new Array(); NFC_east[0]=["Giants", 16, 0, "Eli Manning"]; NFC_east[1]=["Cowboys", 0, 16, "Tony Romo"]; NFC_east[2]=["Redskins", 0, 16, "Donnovan McNabb"]; NFC_east[3]=["Eagles", 0, 16, "Mike Vick"]; that's my array. now i need to display that in a table with a Team column, wins column, loses column, and a quarterback column. i basically want to do this using a for loop, and he gave me a hint about using a nested while loop as well somehow. i know i need to use getElementById, id, and innerHTML stuff but i just don't know how to do it. i cant find anything to help me with this simple task, hoping someone here could help. I am working on a page where the user will select a location from a dynamically generated dropdown list. I was able to create the php multidimensional array (tested and working) from a MySql database using the users information at login, but I'm having problems converting it to a javascript multidimensional array. I need to be able to access variables that I can pass to a number of text fields within an html form. For instance, if a user belongs to a company with multiple addresses, I need to be able to let them select the address they need to prepopulate specific text fields. php array creation: Code: if ($row_locations) { while ($row_locations = mysql_fetch_assoc($locations)) { $mail[$row_locations['comp_id']]=array('mailto'=>$row_locations['mailto'], 'madd'=>$row_locations['madd'], 'madd2'=>$row_locations['madd2'], 'mcity'=>$row_locations['mcity'], 'mstate'=>$row_locations['mstate'], 'mzip'=>$row_locations['mzip'], 'billto'=>$row_locations['billto'], 'badd'=>$row_locations['badd'], 'badd2'=>$row_locations['badd2'], 'bcity'=>$row_locations['bcity'], 'bstate'=>$row_locations['bstate'], 'bzip'=>$row_locations['bzip']); } } javascript function - this should create the array and send variables to text fields. Code: function updateAddress() { var mail = $.parseJSON(<?php print json_encode(json_encode($mail)); ?>); { if (comp_id in mail) { document.getElementById('mailto').value=mail.comp_id.mailto.value; document.getElementById('madd').value=mail.comp_id.madd.value; document.getElementById('madd2').value=mail.comp_id.madd2.value; document.getElementById('mcity').value=mail.comp_id.mcity.value; document.getElementById('mstate').value=mail.comp_id.mstate.value; document.getElementById('mzip').value=mail.comp_id.mzip.value; } else { document.getElementById('mailto').value=''; document.getElementById('madd').value=''; document.getElementById('madd2').value=''; document.getElementById('mcity').value=''; document.getElementById('mstate').value=''; document.getElementById('mzip').value=''; } } } Where is this breaking? Thanks in advance. Hi, i can't find the mistake in my little script hope someone can help me. PHP Code: <?php /* -------------------- read thumbfolder -------------------- */ function isRdyPfD($filename){ if ($filename == '.' || $filename == '..') { // To-Top-Dir return false; } $ext = explode(".",$filename); $ext = $ext[sizeof($ext) - 1]; $allowedformats = array ( 'jpg', 'png', 'jpeg', 'gif' ); return in_array($ext,$allowedformats); } function getPicsfromDir($dir){ /* array with names of the pictures in $dir */ if (is_dir($dir)) { if ($dh = opendir($dir)) { $filearray = array(); while (($file = readdir($dh)) !== false) { if (isRdyPfD($file) === true) { $filearray[] = $file; } } closedir($dh); return $filearray; } } else { return false; } } // End Function $thumbs = getPicsfromDir("./images/thumbs/"); /* -------------------- thumbfolder -------------------- */ echo "<div id='thumbslider'>\n"; echo "<ul id='thumbs'>\n"; for($i = 0; $i < count($thumbs); $i++){ echo "<li><img src=\"./images/thumbs/$thumbs[$i]\" onclick=\"thumbClick($i)\" /></li>\n"; } echo "</ul>\n"; echo "</div>\n"; /* -------------------- big size images folder -------------------- */ $bigSizeImages = getPicsfromDir("./images/"); //print_r($bigSizeImages); $jsValue = ''; for ($j=0; $j < count($bigSizeImages); $j++){ $jsValue = $jsValue . $bigSizeImages[$j]; if ($j < (count($bigSizeImages)-1)) { $jsValue = $jsValue . ","; } } ?> <script type="text/javascript"> images = new Array(<?php echo $jsValue ?>); function thumbClick(pos){ //alert(pos); alert(images[pos]); } </script> I can't trace the images array values? thanks for a feedback!!! Hi, Here is a working code to copy 2d php array to 2d javascript array. Code: <html> <head> <?php for($i = 0; $i < 3; $i++) { for($j = 0; $j < 2; $j++) {$quest[$i][$j] = $i*10+$j;} } ?> <script type="text/javascript"> var questions = new Array(3); for (var i = 0; i < 3; i++) { questions[i] = new Array(2); } questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; document.write(questions[0][0] + "<br />"); document.write(questions[0][1] + "<br />"); document.write(questions[1][0] + "<br />"); document.write(questions[1][1] + "<br />"); document.write(questions[2][0] + "<br />"); document.write(questions[2][1] + "<br />"); </script> </head> </html> Now,here's the thing.Notice these lines in the code questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; I would like to put these lines in a loop,something like for (var i = 0; i < 3; i++) { questions[i] = ["<?php echo join("\", \"", $quest[i]); ?>"]; } But even after a lot of efforts I am unable to do so,what am I doing wrong?Thanks Hi, In a nutshell,can anyone tell me how to copy a 2d (two dimensional ,2 dimensional) php array to 2d javascript array?I would be obliged if anyone can provide me a method of doing that OR I have written a code to copy a 2d php array to a 2d javascript array.It is working but there is one problem(please see the following).Can anyone tell me what I am doing wrong here? The 2d php array is $quest[100][6] and the 2d javascript array is questions[100][6] . I have written the javascript code inside the <?php....?> itself using echo "<script language="javascript" type="text/javascript">.......</script>; Now ,inside the javascript,when I try to copy the 2d php array to the 2d javascript array using the following method it works questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1]= ["<?php echo join("\", \"", $quest[1]); ?>"]; ... and so on However, if I try to do the same using the following method it does not work for (var i= 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } Why is that?What mistake am I making?Any help will be deeply appreciated.Thanks -----------------------------THE CODE------------------------------------ <?php Access database and store result of mysq_query in $result....... $result = mysql_query($query); for ( $count = 0; $count <= 99; $count++) { $quest[$count]=mysql_fetch_array($result,MYSQL_NUM);; } echo "<script language="javascript" type="text/javascript"> var questions = new Array(100); for (var i = 0; i <100; i++) { questions[i] = new Array(6); } /*The following method of copying 2d php array to 2d javascript array is not working for ( var i = 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } */ /*The following method ,however,is working*/ questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"",$quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"",$quest[2]); ?>"]; ....and so on </script>"; mysql_close($db_server); ?> Hello I'm have some javascript objects with arrays that should be transferred as php array. Its posted by ajax httpRequest. How can I return php array, from the javascript? JS Code: ['asd1', 'asd2', 'asd3'] via Ajax => PHP PHP Code: array('asd1', 'asd2', 'asd3'); Hello hello, I have a javascript array to load a different picture each time a page loads up. The code is as follows: <script type="text/javascript"> var imageArray = new Array(); imageArray[0] = "images/animation9.gif"; imageArray[1] = "images/Title2.gif"; imageArray[2] = "images/animation4.gif"; function doIt() { var rand = Math.floor(Math.random()*3); var imgPath = "<img src='"+imageArray[rand]+"' alt='Welcome' border='0' align='absmiddle' />"; document.getElementById("image").innerHTML = imgPath; } </script> So...it works fine with .gifs, but how would I get it to work with .swf movies too? I've tried just putting the .swf in there e.g. ... 'imageArray[2] = "images/animation6.swf"; But that doesn't seem to work. Any ideas? Thank-you SO much in advance. Hi guys, I am new to JavaScript and was wonder how I would go about creating a form to allow the user to enter various words, one at a time. These words are added to an array and displayed in the page using the textarea form element. Each time a new word is entered, it is added to the array, and then the array is sorted in alphabetical order before the words in the array are displayed in the textarea, one per line. I have tried lots and lots of different methods to accomplish this, and I can get it half working when I use the alert function, but I need this to display on the page in a textarea rather than in an alert box, I tried to get it to write to the page using a document.write function, but like I said i am new to JavaScript and unfortunately cant get any of it working. Code: Code: <!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>JavaScript Page One</title> </head> <BODY> <CENTER> <FORM name="history"> <INPUT name="command" type="text" value=""> <INPUT type="button" value="Add to List" onclick="f_store(document.history.command.value)"> <INPUT name="history" type="button" value="Show List" onclick="f_print()"> </FORM> <P> <SCRIPT language="JavaScript"> function MakeArray( n ) { if( n <= 0 ) { this.length = 0; return this; } this.length = n; for( var i = 1; i <= n; i++ ) { this[ i ] = 0; } return this; } var history = new MakeArray( 15 ); var index = 0; var cmmnd = 1; function f_store( sTR ) { var i; if( index >= history.length ) { for( i = 1; i < history.length; i++ ) history[i-1] = history[i]; index = history.length - 1; } history[ index ] = cmmnd + ":" + sTR; ++cmmnd; ++index; document.history.command.value=""; } function f_print() { var allCmmnds, i; allCmmnds = ""; for( i = 0; i < index; i++ ) allCmmnds += history[i] + "\n"; alert( allCmmnds ); } </SCRIPT> </body> </html> If someone could please help me by posting some relevant code that would accomplish this, I would greatly appreciate it, as so far I have been scratching my head for a few hours. Thanks, ~Savage PLEASE help me with this I have no hair left! Thanks a million, RHonda <!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"> #container { background-color:#FFFF99; width:90%; } #header { background-color: #FFFF99; } #topNav { background-color: #FFFF99; } #content { background-color: #FFFF99; width:70%; float:left; } #displayCart { background-color:#9CC; width:28%; float:right; } #footer { background-color: #FFFF99; clear:both; } </style> </head> <body> <div id="container"> <div id="header"> <h2 align="center">WDV221 Project 11 </h2> <h2 align="center">Arrays Part 3</h2> </div> <div id="topNav"> <div align="center"> <table width="80%" border="0"> <tr> <td>Home</td> <td>Products</td> <td>Services</td> <td>About</td> </tr> </table> </div> </div> <div id="content"> <div align="center"> <h3>Available Product Selection </h3> <table width="80%" border="0"> <tr> <td><div align="center">Pencils</div></td> <td><div align="center">Pens</div></td> <td><div align="center">Scissors</div></td> <td><div align="center">Markers</div></td> <td><div align="center">Stapler</div></td> <td><div align="center">Coffee Cup</div></td> </tr> <tr> <td><div align="center">$.45</div></td> <td><div align="center">$1.19</div></td> <td><div align="center">$8.95</div></td> <td><div align="center">$4.88</div></td> <td><div align="center">$12.97</div></td> <td><div align="center">$3.00</div></td> </tr> <tr> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> <td><div align="center"> <input name="" type="button" value="Add to Cart" /> </div></td> </tr> </table> <p><input name="" type="button" value="Display Cart" /></p> <p><input name="" type="button" value="Remove Item From Cart" /></p> </div> <h2>Instructions</h2> <p> This project will build a Javascript base shopping cart. The scripts will add product and price to a pair of parallel arrays. It will allow the user to view the shopping cart elements, shopping cart totals and remove elements from the shopping cart. </p> <p>For purposes of this exercise we will limit the shopping cart to a maximum of 5 items. Once it has reached five items the Add a Product function will no longer allow you to add products. </p> <ol> <li>Create two parallel arrays called productName productPrice. The arrays<br /> should only allow for five rows. <br /> <br /> </li> <li>Build a function that will add the product name and product price to a row in their respective arrays. This function will activate on the Add to Cart buttons.<br /> <br /> <strong>Note</strong>: This is a great opportunity to make this a generic function and pass the product name and price into the function as parameters. The<br /> function would use the two parameters to lookup the product and<br /> place the price in the corresponding row.<br /> <strong>example</strong>: onclick="addToCart("<em>product</em>",<em>price</em>)<br /> <br /> <strong>HINT</strong>: Keeping track of the rows is best done with a global variable. <br /> <strong>Note</strong>: Duplicate rows are allowed. <br /> <strong>Example</strong>: productName[0] and productName[2] could both contain<br /> Stapler. <br /> </li> <li>Build a function to display the arrays in the Shopping Cart area. This will run when the Display Cart button is clicked. It will also provide a total of the product prices. The total should be formatted as currency.<br /> <strong>Hint</strong>: Use <p> and .innerHTML to build an area to display and clear</li> <li>Build a function that will remove a product from the arrays. It will ask the user for the product name. The name should not be case sensitive. Remove the product and the corresponding price.</li> <li>Build a function that will remove all the products and corresponding prices from the arrays. This will run when the Clear Cart button is clicked.</li> </ol> </div> <div id="displayCart"> <h4 align="center">Shopping Cart</h4> <h4 align="center">List of Products</h4> <p align="center"><input name="" type="button" value="Clear Cart" /></p> <p>Today is: Month/dd/yyyy</p> </div> <div id="footer">Place today's date he (Day, Month date, year) ex: Monday January 1, 2012</div> </div> </body> </html> Hi, Can anyone help me with this question? I have a JavaScript page to place a track to a google maps. I want the array of points to be shown to come from PHP. However, there are (probably a lot) of errors in it that makes it doesn't work. My main page code: xmlhttpT=new XMLHttpRequest(); //var MyRouteC = ""; xmlhttpT.open("GET","getRoute.php",true); //var MyRouteC= (array)xmlhttpT.responseText; var MyRouteC = (array)xmlhttpT.responseText); xmlhttpT.onreadystatechange=function() { if (xmlhttpT.readyState==4) { //MyRouteC = xmlhttpT.responseText; alert(xmlhttpT.responseText); } } xmlhttp.send(); var MyRoute = new google.maps.Polyline({ path: MyRouteC, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 }); MyRoute.setMap(map); The page it is calling is a php page: PHP Code: <?php $con = mysql_connect("xxxxx.mysql","xxxxxxxxxxx","xxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("letsmeet_mobi", $con); $query = "SELECT * FROM CurrentLocation ORDER BY time DESC LIMIT 0 , 5"; mysql_query($query); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $output = $output . " new google.maps.LatLng(".$row['gpslat'].", ".$row['gpslong']."), "; } echo $output; mysql_close($con); ?> The php data connection works fine, and it results in a string that looks exactly like the way I want the value to be passed to the JavaScript. Any help is welcome! Sorry folks, Im not sure that I am using the correct terminology here. What i would like to do is sort an array based on the [SortBy] value, however this array is nested. For instance: ar.[SortBy]"PartNumber" ar.[0].[PartNumber]"123" ar.[0].[PartName]"Widget1" ar.[1].[PartNumber]"345" ar.[1].[PartName]"Widget2" ar.[2].[PartNumber]"456" ar.[2].[PartName]"Widget3" ar.[3].[PartNumber]"567" ar.[3].[PartName]"Widget4" Thanks! I have a code that I implemented on my site. I was wondering if there was a way to had an active link within the 'blurb' section? I'm not familiar with Javascript... var blurb = new Array(); blurb[0]="Text 1" blurb[1]="Text 2" blurb[2]="Text 3" blurb[3]="Text 4" blurb[4]="Text 5<br>More text<br>Add a link" blurb[5]="www.link.com" for (i=0; i < aryImages.length; i++) { var preload = new Image(); preload.src = aryImages[i]; } function swap(imgIndex) { document['imgMain'].src = aryImages[imgIndex]; TheText = blurb[imgIndex]; document.getElementById('blurbarea').innerHTML=TheText; } Any help would be great!! Hi guys I was wondering if its possible to add contents within a div to a javascript array. Something like this: Code: <script type="text/javascript"> function returnArray() { var divContent = document.getElementById('images'); var matchImage = divContent.match(/<img/); /* add images into array somehow */ alert('This is ' +ImageArray[1]); } </script> <div id="images"> <img src="image1.jpg" alt="image" /> <img src="image2.jpg" alt="image" /> <img src="image3.jpg" alt="image" /> </div> Thanks for any info. Hello, I have just started learning JavaScript, so I do not know much about it at this moment. I need some help regarding validation of input values which are actually in an array. Okay, my HTML looks like this: Code: Link# 1: <input name="url[]" size="80" type="text"> Title# 1:<input name="title[]" size="80" type="text"> Link# 2: <input name="url[]" size="80" type="text"> Title# 2:<input name="title[]" size="80" type="text"> Link# 3: <input name="url[]" size="80" type="text"> Title# 3:<input name="title[]" size="80" type="text"> . . . . . And so on. (up to 20) User can add more input fields by adding "Add" button; I'm using JavaScript for that purpose. By default, only a couple of fields is shown. I want to validate these all fields using a loop or a number of loops, such that an alert appears if any field is left blank and also if any value in title[] array matches another value in that array and same for the second array url[] Examples of working would be something like this: Code: If Link# 1 is left blank: alert("Link# 1 is empty"); or If Link# 2 is left blank: alert("Link# 2 is empty"); or If Title# 1 is left blank: alert("Title# 1 is empty"); or If Title# 2 is left blank: alert("Title# 2 is empty"); or If Link# 1 == Link# 2: alert("Link# 1 is same as Link#2"); or If Link# 1 == Link# 3: alert("Link# 1 is same as Link#2"); or If Title# 1 == Title# 3: alert("Title# 1 is same as Title#3"); etc, etc. Any help would be appreciated. Thank you. I am new to learning JS and am trying to create an array through a prompt. It seems to work, but I believe it is treating the prompted numbers as strings not numbers. I am parsing the negatives and zeros, and positives and counting them. It doesn't recognize the negative sign. Here's my js: function counter() { var numArr = new Array(Number(prompt("Please enter and array of numbers, in any order, separated by a comma..." + '\n' + "In the following format: -2,0,2"))); var positives = 0; var negatives = 0; var zeros = 0; for (var i = 0; i < numArr.length; i++) { switch (true) { case numArr[i] < 0: negatives++; break; case numArr[i] == 0: zeros++; break; case numArr[i] > 0: positives++; break; } } alert("You entered:"+ '\n' + "Number of Negatives: " + negatives + '\n' + "Number of Zeros: " + zeros + '\n' + "Number of Positives: " + positives); } counter(); Any suggestions? Hi All, I'd be truly grateful if anyone can help me (a not so good JavaScripter). I'm trying to adapt some code. I have 3 chained select boxes which when the third is selected, I'd like to display specific info from the array within the HTML via the 'info' div. It works, but displays the whole array entry, and I'd just like to pick certain info from that entry. You can see my efforts within the 'categories["Nonfiction"]' entry - I've added the extra array elements to add another dimension to the array, but I think I've got into a muddle - can anyone help? So... when a user selects BOOKS > NONFICTION > COOKBOOKS I'd like just the 'Extra info 01' & 'Extra info 02' text to appear within the 'info' div. 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> <title>Interdependent Select Menus</title> <script type="text/javascript"> var categories = []; categories["startList"] = ["Books", "Clothes"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = [["How-To", "Extra info 01", "Extra info 02"], ["Cookbooks", "Extra info 01", "Extra info 02"], ["Travel", "Extra info 01", "Extra info 02"] ]; categories["Clothes"] = ["Men","Women","Children"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['List'+i].selectedIndex = 0; } var nCat = categories[currCat]; for (each in nCat) { var nOption = document.createElement('option'); var nData = document.createTextNode(nCat[each]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { document.getElementById("info").innerHTML = L1 + "\n" + L2 + "\n" + L3; } function init() { fillSelect('startList',document.forms['tripleplay']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="tripleplay" action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <br /> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <br /> <select name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >Make a selection</option> </select> <div id="info">This is the default text</div> </form> </body> </html> Hey all, I read this tutorial about creating javascript tabs: http://www.elated.com/articles/javascript-tabs/ Now basically there is a tabLinks array (var tabLinks = new Array(). There is a variable called id, which is assigned the value of the href attribute of a link ( we are looping through an array of links and tabLink represents the current link). In the code, there is a line: Code: "tabLinks[id] = tabLink; So id refers to the href attribute value of the link (without a hash) and tabLink is the link itself. tabLinks is the array. My question is are both the attribute and the link itself getting indexed at position 0 of the array, for example? Or is just the link getting indexed? If so, then why have this: [id]? I can't imagine that they are both getting indexed at position 0: [about a]. But if it's just the id getting indexed [about], then why are we assigning the link to this specific index? As you can tell, I'm really confused about how this indexing is working. Thanks for any response. Hello all, There's this javascript array on an html page, with some gifs in it. How can I include swfs in this array? Here's the code: <script type="text/javascript"> var imageArray = new Array(); imageArray[0] = "images/animation9.gif"; imageArray[1] = "images/Title2.gif"; imageArray[2] = "images/animation4.gif"; function doIt() { var rand = Math.floor(Math.random()*3); var imgPath = "<img src='"+imageArray[rand]+"' alt='Welcome to Kabeoke' border='0' align='absmiddle' />"; document.getElementById("image").innerHTML = imgPath; } </script> Thank-you SO much in advance |