JavaScript - Indexing In A Javascript Array
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. Similar TutorialsI 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'); 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! 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> 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. 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? Hey all, first, if I missed this in my search, I apologize. Now on to the problem at hand. I'm reading an xml file of html links into a webpage I'm building on the intranet. I have assigned each of a particular element of that xml file to a specific location within a javascript array. Then I built a second javascript array and assigned the value of the first array to second array using the .toString(); method. Here's an example of what I've got so far: Code: var linkArray = new Array(); linkArray[0] = (xmlDoc.getElementsByTagName("link")[0].childNodes[0].nodeValue); linkArray[1] = (xmlDoc.getElementsByTagName("link")[1].childNodes[0].nodeValue); linkArray[2] = (xmlDoc.getElementsByTagName("link")[2].childNodes[0].nodeValue); linkArray[3] = (xmlDoc.getElementsByTagName("link")[3].childNodes[0].nodeValue); linkArray[4] = (xmlDoc.getElementsByTagName("link")[4].childNodes[0].nodeValue); linkArray[5] = (xmlDoc.getElementsByTagName("link")[5].childNodes[0].nodeValue); linkArray[6] = (xmlDoc.getElementsByTagName("link")[6].childNodes[0].nodeValue); linkArray[7] = (xmlDoc.getElementsByTagName("link")[7].childNodes[0].nodeValue); var pageArray = new Array(); pageArray[0] = linkArray[0].toString(); pageArray[1] = linkArray[1].toString(); pageArray[2] = linkArray[2].toString(); pageArray[3] = linkArray[3].toString(); pageArray[4] = linkArray[4].toString(); pageArray[5] = linkArray[5].toString(); pageArray[6] = linkArray[6].toString(); pageArray[7] = linkArray[7].toString(); I have put documentDOTwriteln statements in at various places to test the values of both arrays to be sure they are the same and they are. Now, later in the code, I'm loading an iframe that targets a specific element of the second array for the page link. It does this through a variable called currentPage thus: theIframe.src = pageArray[currentPage]; where currentPage is previously assigned a value pointing to an element in the array. For example currentPage = 0;. I'm trying to replace the original code which looks like this and works: Code: var pageArray = new Array(8); pageArray[0] = "html/chapters/chapter1_Introduction/chapter1.html"; pageArray[1] = "html/chapters/chapter2_Change-Location/chapter2.html"; pageArray[2] = "html/chapters/chapter3_Change-Manager/chapter3.html"; pageArray[3] = "html/chapters/chapter4_Change-Salary/chapter4.html"; pageArray[4] = "html/chapters/chapter5_Change-Assignment/chapter5.html"; pageArray[5] = "html/chapters/chapter6_Termination/chapter6.html"; pageArray[6] = "html/chapters/chapter7_Request-Access-to-MSS/chapter7.html"; pageArray[7] = "html/chapters/chapter8_Summary/chapter8.html"; with the contents of the xml file so I can load different pages into a template. I don't understand what I'm doing wrong. Can anyone point me in the right direction? I believe my xml is parsing correctly since I can do a documentDOTwriteln and see the contents when placed into an array. Am I wrong on this? Any and all help you can give is greatly appreciated! M 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. Its a ads rotation code: Don know why it doesnt work... Code: <body> <div align="center"> <script> var brw=navigator.appName; var id; if(brw == "Netscape") id=1; if(brw =="Microsoft Internet Explorer") id=2; if(brw == "Opera") id=3; var delay=10000; var k=0; var fcontent=new Array(); var b=new Array(); function go(k) { b[0]='' b[1]='<iframe src="http://........." width="460" height="60" scrolling="no" name="cpm" frameborder="0"></iframe>' b[2]='<iframe width="468" height="60" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' b[3]='<iframe width="468" height="120" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' if(id != 3) b[4]='<iframe width="1" height="1" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://......."></iframe>' else b[4]='' b[5]='..' ..... ..... b[36]='.... ' return; } begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations fcontent[0]=b[0]+b[1]+b[2]+b[3]+b[4]+b[5]; fcontent[1]=b[6]+b[7]+b[8]+b[9]+b[10]; fcontent[2]=b[11]+b[12]+b[13]+b[14]+b[15]; fcontent[3]=b[16]+b[17]+b[18]+b[19]+b[20]; fcontent[4]=b[21]+b[22]+b[23]+b[24]+b[25]; fcontent[5]=b[26]+b[27]+b[28]+b[29]+b[30]; fcontent[6]=b[31]+b[32]+b[33]+b[34]+b[35]; fcontent[7]=b[0]+b[36]; closetag='</div>'; var ie4=document.all&&!document.getElementById; var DOM2=document.getElementById; var index=0; //function to change content function changecontent(){ if (index>=fcontent.length ) { index=0; ++k;delay=delay+5000; } go(k); if(delay>15000){return;} if (DOM2){ document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag } else if (ie4) { document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag; } ++index; setTimeout("changecontent()", delay); } if (ie4||DOM2) document.write('<div id="fscroller" style="width:700px;"></div>'); if (window.addEventListener) window.addEventListener("load", changecontent, false) else if (window.attachEvent) window.attachEvent("onload", changecontent) else if (document.getElementById) window.onload=changecontent </script> </div> </body> here go(k); function might do this mass (output-->NaN). plz b a help... 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 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! 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> 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. Hi all, this is my first post to this great useful forum. I have a javascript 2d array [x,y] that contains integer values like this: [0,0], [0,1], [0,2], [0,3], [1,0], [1,1], [1,2], [2,0], [2,1], [2,2], [0,-1], [0,-2], [0,-3], [1,-1], [1,-2], [2,-3] my question is how to get the max,min y value for each x. for the sample above it should give me another array with the following results [0,3],[0,-3],[1,2],[1,-2],[2,2],[2,-3] your help is highly appreciated Regards Omran 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.. I want to have a list of words (in an array or whatever just to work) if the user put that word in a textfield (onblur or onchange) a message popup (alert) appears. (Must be popup alert) but I dont know to code it. HELP! ex.: Code: function badwords() { var badwords = new Array(); badwords =["badwords1","badwords2","AndSo-On"]; if badwords if written in textfield alert("Badwords not allowed"); else nothing happen just continue with next textfield } <input type="text" name="" onBlur=badwords()> Anyone please help |