JavaScript - Altering Color And Adding Coordinates To An Array In Javascript
Hi all,
I have a div element (i.e. <div id="main">) that contains a number of links, each with white background colors and its top and left style properties set to different values. I need to do several things with the anchors when they are clicked: When a white anchor is clicked, its background color is turned yellow and its coordinates (top and left style property values) are added to an array. The coordinates for a single anchor is to be separated by a hyphen; coordinates for multiple anchors are to be separated by a comma (eg. "0-9,0-18") When a yellow anchor is clicked, its background color is turned white and its coordinates are removed from the array. The values in the array are to be the value for a hidden input element, all separated by commas. I'm a Javascript novice and don't know where to begin. Can someone help me with this? Thanks in advance, Dude-Dastic Similar TutorialsHi Im taking a course in web design and am working on a basic javascript page. I have a drop down box where you select a item and it opens a new window. How would I get the back ground color to be the same as the web page color (lightblue), what code would I use and where in my code would I put it? [CODE] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>MEG</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- var content; var oneWindow; var fullWindow; var oneWindowStatus = false; var fullWindowStatus = false; function closeAllWindows() { if((oneWindowStatus) && (!oneWindow.closed)) oneWindow.close(); if((fullWindowStatus) && (!fullWindow.closed)) fullWindow.close(); oneWindowStatus = false; fullWindowStatus = false; } function productObject(name,description,use,image) { this.name = name; this.description = description; this.use = use; this.image = image; this.displayOne = displayOne; } //Add products here var products = new Array(); products[0] = new productObject("Ears", "Fluffy, pointy, big", "For hearing other dogs near by, for listening to my owner but ignoring her", "images/ears.jpg"); products[1] = new productObject("Eyes", "Shiny, brown, pretty", "To see dogs to bark at, to see when treats are available", "images/eyes.jpg"); products[2] = new productObject("Nose", "Black, wet", "For sniffing out food and squirrels", "images/nose.jpg"); products[3] = new productObject("Mouth", "BIG", "For barking loudly with", "images/mouth.jpg"); products[4] = new productObject("Tongue", "Pink, wet", "To lick you with when you really dont want her to", "images/tongue.jpg"); products[5] = new productObject("Legs", "Short, fluffy", "To run as fast as possible with after squirrels", "images/legs.jpg"); products[6] = new productObject("Paws", "Small", "To raise when I want treats/food of any sort", "images/paws.jpg"); var len = products.length; function displayOne() { content=""; content+="<HTML><HEAD><TITLE>" + this.name + "</TITLE></HEAD>"; content+="<BODY><DIV ALIGN='center'>"; content+="<TABLE WIDTH='90%'><TR><TD COLSPAN='3' ALIGN='center'>"; content+="<H3>Name: " + this.name.bold() + "</H3><HR>"; content+="<TR><TD><B>Name:</B> " + this.name; content+="<TR><TD><B>Description:</B> " + this.description; content+="<TR><TD><B>Use:</B> " + this.use; content+="<TR><TD><IMG SRC= '" + this.image + "' HEIGHT='100' WIDTH='100'>"; content+="</TABLE><FORM>"; content+="<INPUT TYPE='button' VALUE='OK' onClick='window.close();'>"; content+="</FORM></DIV></BODY></HTML>"; oneWindow = open("","OneWindow","width=500,height=400"); newWindow(oneWindow); oneWindowStatus = true; } function showAll() { content=""; content+="<HTML><HEAD><TITLE>All that is Meg</TITLE></HEAD>"; content+="<BODY><DIV ALIGN=center>"; content+="<TABLE WIDTH='90%' BORDER CELLPADDING='2'>"; content+="<TR><TH COLSPAN='2' ALIGN='center'>"; content+="All that is Meg"; content+="<TR><TH>Name<TH>Image"; for (var i = 0; i < len; i++) { content+="<TR><TD>"; content+="<A HREF='javascript:void(window.opener.products[" + i + "].displayOne());'>"; content+=products[i].name + "</A>"; content+="<TD>" + products[i].description; } content+="</TABLE><FORM>"; content+="<INPUT TYPE='button' VALUE='OK' onClick='window.close();'>"; content+="</FORM></DIV></BODY></HTML>"; fullWindow = open("","AllWindow","width=500,height=400,resizable=1"); newWindow(fullWindow); fullWindowStatus = true; } function newWindow(x) { x.document.close(); x.document.open(); x.document.write(content); x.document.close(); x.moveTo(20,20); x.focus(); } //--> </SCRIPT> </SELECT> </HEAD> <BODY onFocus="closeAllwindows();" bgcolor="lightblue"> <DIV ALIGN="center"> <H2>Meg</H2> <HR> <FORM NAME="prodForm"> <TABLE WIDTH="100%"> <TR> <TD WIDTH="50%" ALIGN="right"> <SELECT NAME="itemName"> <SCRIPT LANGUAGE="JavaScript"> <!-- for (var i = 0; i < len; i++) { document.write("<OPTION>" + products[i].name); } //--> </SCRIPT> </SELECT> <TD> <INPUT TYPE="button" VALUE="Get Info" onClick=" var i = document.prodForm.itemName.selectedIndex; products[i].displayOne();"> <TR><TD ALIGN="right"> <TR><TD colspan="2" ALIGN="center"> <TR><TD colspan="2" ALIGN="center"> <INPUT TYPE="button" VALUE="Show All Products" onClick="showAll();"> </TABLE> </FORM> <img src="images/meg1.jpg" "alt="Meg" border="2"/> </DIV> </BODY> </HTML> [CODE] Thanks and hope someone can help Claire Hi! New to JS... have been trying to rework this to call additional, independent sets of colors to cycle through (so it would loop thru a set of grays, a set of primary colors, etc). I would use perhaps a different function name in the HTML to call different sets of colors. If this is more complex than I think it is, I think 3 sets would be plenty. Would be hugely grateful for any help, thanks so much in advance. (demo link of script in current state at bottom) Code: <html><head><title></title> <script language=javascript> colors = ["#cacdca", "#b2b4b2", "#969896", "#7d7f7d", "#ffff00"]; cRGB = []; function toRGB(color){ var rgb = "rgb(" + parseInt(color.substring(1,3), 16) + ", " + parseInt(color.substring(3,5), 16) + ", " + parseInt(color.substring(5,7), 16) + ")"; return rgb; } for(var i=0; i<colors.length; i++){ cRGB[i] = toRGB(colors[i]); } function changeColor(target){ var swapper = navigator.appVersion.indexOf("MSIE")!=-1 ? toRGB(document.getElementById(target).style.backgroundColor) : document.getElementById(target).style.backgroundColor; var set = false; var xx; for(var i=0; i<cRGB.length; i++){ if(swapper == cRGB[i]){ if(((i+1)) >= cRGB.length){ xx = 0; }else{ xx = i+1; } document.getElementById(target).style.backgroundColor = colors[xx]; document.getElementById(target).style.backgroundImage.show; set = true; i=cRGB.length; } } set ? null : document.getElementById(target).style.backgroundColor = colors[1]; } </SCRIPT> </head> <body bgcolor="#333333"> <div> <div id="a1" onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background1.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: none"></div> <div id=a2 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background2.gif); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div> <div id=a3 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background3.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div></div> </body> </html> Demo: http://theclutch.com/rollover_color_..._bgndimage.htm Hi, I'm faced with a problem trying to set background color under IE7. I have the following Javascript: Code: function showLayer793BKColor(id) { var txtObj = document.all(id); if (txtObj.style.display == 'none') { txtObj.style.display = '' txtObj.style.backgroundColor = 'grey'; } } function hideLayer793BKColor(id) { var txtObj = document.all(id); if ( txtObj.style.backgroundColor == 'grey' ) txtObj.style.display = 'none'; } These functions are used to show or hide div blocks. These blocks are, for example, specified in the following way: Code: <div id="l_gct5tekst" style="display:none"> <b>GCT 5. Eerste verkenning problematiek</b> and, for example, Code: <div id="l_Keuze" style="display:none"> <br/> <b>GCT 5</b> <br/> </div> The whole configuration works smoothly when using IE8. However, when using IE7 I get an error msg like "Invalid value for property". When I use the Color propert iso the BackgroundColor property I get no error anymore but of course I don't have a background color anymore then. In what way can I specify the use of a background color under IE7 ? Or is just not possible in one way or the other. Furthermore, what more differences between JS under IE7 and IE8 do I have to take into account ? Do I also have to rewrite my div block in some way (using some attribs ?) to cope with IE7 ? Thanks in advance, Diederick van Elst My site will change color schemes when a user presses the button in the top left. I want to add a third theme though. I can't figure it out though. My html as relevent Code: <!--EXTERNAL FILES--> <link rel="stylesheet" type="text/css" href="main.css" /> <!--[if IE]><link rel="stylesheet" type="text/css" href="mainIE.css" /><![endif]--> <link id="altstyle" rel="stylesheet" type="text/css" href="main.css" /> <script type="text/javascript" src="main.js"></script> <!--STOP EXTERNAL FILES--> <title>Votillity.com</title> <!--CSS INTERNAL--> <!--CSS INTERNAL--> <!--JAVASCRIPT INTERNAL--> <!--JAVASCRIPT INTERNAL--> </head> <body onload="startTime()"> <img class="Zindexsty1" style="position: fixed; top: 0px; left: 0px;" src="http://votillity.com/VotillityLogo1.png" alt="VOTILLITY" /> <img class="Zindexsty2" style="position: fixed; top: 0px; left: 0px;" src="http://votillity.com/VotillityLogo2.png" alt="VOTILLITY" /> <button id="altstyact" class="button" style="position: fixed; top: 0px; left: 170px; width: 60px;">Theme</button> Javascript Code: //ALTERNATE STYLES function changeStyle() { var obj1=document.getElementById('altstyact'); var obj2=document.getElementById('altstyle') test=true; obj1.onclick=function() { test==true? (obj2.href='main2.css',obj1.firstChild.nodeValue='Classic',test=false): (obj2.href='main.css',obj1.firstChild.nodeValue='Ice',test=true) } } if(window.addEventListener) { window.addEventListener('load',changeStyle,false); } else { if(window.attachEvent) { window.attachEvent('onload',changeStyle); } } //STOP ALTERNATE STYLES I don't think you need the css's. If, however, I'm wrong just let me know. Keep in mind that the javascript is external. Here's my site if you need a better look Votillity Thank you OK, I appologise in advance if this post is long, but I need this answer, as I'm at my wits end. So I have this code Code: function SizeSelect(){ if(document.getElementById("JarSize").value=="Small") document.getElementById("JarPrice").innerHTML="3.00" else if(document.getElementById("JarSize").value=="Medium") document.getElementById("JarPrice").innerHTML="5.00" else if(document.getElementById("JarSize").value=="Large") document.getElementById("JarPrice").innerHTML="7.00" } Which alters the value of JarPrice, based on which JarSize is selected. Which is the code below here. Code: <select id="JarSize" onchange="SizeSelect();"> <option value="Small" >Small</option> <option value="Medium">Medium</option> <option value="Large">Large</option> </select> <span class="price">$<span id="JarPrice">3.00</span></span></div> Now for the hard part. I need this piece of code Code: <a href="javascript:;" onclick="simpleCart.add('name=Mango and Papaya', 'price=5', 'quantity=1');" class="prod_buy">add to cart</a> to be flexible, so that what ever value JarPrice becomes, that 'price=5' becomes the same. Now, the first piece of code is in a seperate .js file to the other two parts, which sit inside a regular HTML page. As I said, I'm desperate, as this is the only part of my site that isn't working ATM And if you need more information about any part, please don't hesitate to ask, as I will be able to give as much info as I can. Hi, I am stumped. I have been trying unsuccesfully for three days to figure something out, and it has brought me here. I am a noob javascripter, so please bear with me. I have created a page with an input button that refers to a function: Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> <meta name="created" content="Thu, 26 May 2011 03:39:57 GMT"> <meta name="description" content=""> <meta name="keywords" content=""> <title>Meltmedia Web Intern Test</title> <style type="text/css"> <!-- body { color:#000000; background-color:#FFFFFF; } a { color:#0000FF; } a:visited { color:#800080; } a:hover { color:#008000; } a:active { color:#FF0000; } --> </style> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <LINK REL=StyleSheet HREF="what.css" TYPE="text/css" MEDIA=screen> <script type="text/javascript"> //function ChangeBackground() <!--{ // document.getElementById("column2").style.backgroundColor="#ffbdaa"; // document.getElementById("row1").style.backgroundColor="#ffbdaa"; // document.getElementById("row3").style.backgroundColor="#ffbdaa"; // document.getElementById("row4").style.backgroundColor="#ffbdaa"; // document.getElementById("mainbody").style.backgroundColor="#f7d7cd"; // } --> function ChangeBackground() { var colors = document.getElementsByClassName("changeme"); //alert(colors.length); for (var i = 0; i < colors.length; i++) { if (colors[i].className="changeme") { colors[i].style.backgroundColor="ffbdaa"; } } } //if (document.getElementsByClassName('changeme')[5].style.backgroundColor="#e8e8e00") { // document.getElementsByClassName('changeme')[5].style.backgroundColor="#ffbdaa"; // } //div1 original color is #e8e8e8 //div2 original color is #e2ebe4 //tablerows original color is #ccddd0 </script> </head> <body> <div id="mainbody" class="changeme"> <img id="header" src="osx_header.jpg"> <div id="inset"> <div id="column1" class="column1"> <p class="text0">Lorem Ipsum Dolor Sit Amet</p> <p class="text1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed est et mi varius euismod sed nec neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultricies pulvinar lacinia. <a href="http://www.google.com/" rel="nofollow" target="_blank" style="color:blue">This is a link.</a> </p> <p class="text1" style="font-size:16px;">Lorem Ipsum Dolor Sit Amet</p> <p class="text1">Sed a felis et eros gravida dignissim. Quisque lobortis magna non purus vulputate pellentesque. Mauris sit amet felis felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam molestie lacinia arcu vitae pretium.<sup>2.3</sup> </p> <div id="unordered_list"> <ul id="blue_bullets"> <li>Vestibulum ante erat, laoreet quis pellentesque quis, tincidunt fermentum turpis. <li>Maecenas in mollis massa. <ul> <li>Ut tempus tincidunt molestie. Phasellus eget nulla id erat scelerisque porttitor vel pharetra nibh. <li>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </ul> <li>Aenean ligula massa, tempor sed pulvinar sit amet, imperdiet a nisi. </ul> </div><!--end of ordered list--> <div id="button"> <!-- <img src="btn-click-here.gif"> --> <input type="button" onClick="ChangeBackground()" value=" "> </div><!--end of button--> <table id="table1"> <tr id="firstrow"> <th id="row1" class="changeme"></th> <th id="row2" class="changeme"><strong>header1</strong></th> <th id="row3" class="changeme"><strong>header2</strong></th> <th id="row4" class="changeme"><strong>header3</strong></th> </tr> <tr> <td>one</td> <td>1234</td> <td>bears</td> <td>abcd</td> </tr> <tr> <td>two</td> <td>5678</td> <td>beets</td> <td>efgh</td> </tr> <tr> <td>three</td> <td>9101</td> <td>battlestar</td> <td>ijkl</td> </tr> <tr> <td>four</td> <td>1121</td> <td>galactica</td> <td>mnop</td> </tr> </table> <!--end of table--> <ol class="ordered"> <li>Integer molestie sodales risus eu commodo. <i>Duis eget est dapibus neque congue</i> accumsan id eu nibh. </li> <li>Proin malesuada hendrerit lobortis. Integer et erat leo. Praesent nec justo nulla. <i>Sed in dolor id neque faucibus consequat.</i> </li> <li>Vestibulum sit amet justo id <strong>risus tempus ornare.</strong> Etiam faucibus urna volutpat lorem dictum imperdiet. </li> </ol> </div> <!--end of column1--> <div id="column2" class="changeme"> <p class="text00"><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</strong></p> <p class="text2">Aenean sed est et mi varius euismod sed nec neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultricies pulvinar lacinia. Sed a felis et eros gravida dignissim. Quisque lobortis magna non purus vulputate pellentesque.</p> <p class="text2">Mauris sit amet felis felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam molestie lacinia arcu vitae pretium. Vestibulum ante erat, laoreet quis pellentesque quis, tincidunt fermentum turpis. Maecenas in mollis massa. Ut tempus tincidunt molestie.</p> <p class="text2">Phasellus eget nulla id erat scelerisque porttitor vel pharetra nibh. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean ligula massa, tempor sed pulvinar sit amet, imperdiet a nisi. Nulla ullamcorper posuere dolor, ac rutrum velit sollicitudin ac. Ut felis leo, ultricies a bibendum ac, luctus semper massa.</p> </div> <!--end of column2--> </div> <!--end of inset--> </div> </body> </html> i would like to change certain style elements of the array each time the button is clicked. I have 5 color sets i would like use for the page, so i would like the button to trigger the color change in a loop, ie when the last color group is reached, the next click returns to the original color set and it continues again. This is a demo page, not for actually publication. I am trying to teach myself javascript and this is an idea that came to me. The things i want to change are the background color of two div's and the top row of a table. My style sheet is seperate, and I will also do the same for the javascript once I can get it to work properly. Thank you in advance for any help. Hi, the source code on the website below i want to know what do i need to change to get the date to show as dd/mm/yyyy instead of mm/dd/yyyy? http://www.nsftools.com/tips/DatePickerTest.htm thanks for your help I'm creating a menu using html, css and a javascript, I found a tutorial to follow online. What I am trying to achieve is when the mouse hovers over the menu items, each item will have a different colour background. the problem is that i can do this but it only works with one colour and not different colours. this is the html: Code: <ul> <li><a href="1.php">Things</a></li> <li><a href="2.php">Animals</a> <ul> <li><a href="2-1.php">Cani</a> <ul> <li><a href="2-1-1.php">Domestic dogs</a></li> <li><a href="2-1-2.php">Wolves</a></li> </ul> </li> <li><a href="2-2.php">Felidae</a> <ul> <li><a href="2-2-1.php">Domestic cats</a></li> <li><a href="2-2-2.php">Wild cats</a></li> </ul> </li> </ul> </li> <li><a href="3.php">Humans</a></li> </ul> the css is as follows: Code: div#s1 { width: 200px; /* menu width */ } div#s1 ul { background-color: #036; list-style-type: none; /* get rid of the bullets */ padding:0; /* no padding */ margin:0; /* no margin for IE either */ } div#s1 ul li { margin: 0; padding: 0; background-color: #036; display:block; border-top: 1px solid white; /* lines */ } div#s1 ul li a { display: block; /* lines extend to right, make area clickable */ color: white; background-color: #036; padding: 3px 3px 3px 23px; margin:0; text-decoration: none; height:15px; /* hint for IE, alternatively remove whitespace from HTML */ } div#s1 ul ul li a { margin-left: 20px; /* indent level 1 */ } div#s1 ul ul ul li a { margin-left: 40px; /* indent level 2 */ } div#s1 ul ul ul ul li a { margin-left: 60px; /* indent level 3 */ } div#s1 li ul, div#s1 li.open li.closed ul { display: none; /* collapse */ } div#s1 li.open ul { display: block; /* expand */ } div#s1 ul li.open a { background-image: url(bullet_open.gif); background-repeat: no-repeat; } div#s1 ul li.closed a { background-image: url(bullet_closed.gif); background-repeat: no-repeat; } div#s1 ul li.leaf a { background-image: url(bullet_leaf.gif); background-repeat: no-repeat; } div#s1 li.active a { background-position: 0px -20px; color: red; /* highlight text */ } div#s1 li.active li a { background-position: 0px 0px; color: white; /* fix lower levels */ } div#s1 ul li a:hover { color: red; background-color: #06C; /* rollover effect */ } and finally the javascript: Code: var menu_active_class = "active"; var menu_leaf_class = "leaf"; var menu_open_class = "open"; var menu_closed_class = "closed"; //the default page that is displayed if URL ends in / var menu_default_page = "index.php"; var menu_url; //main function //menu_id : id of the element containing the navigation function menu_main(menu_id) { var url = location.href; if (url.lastIndexOf("/") == (url.length-1)) { url = url+menu_default_page; } if (url.lastIndexOf("?") >= 0) { url = url.substring(0, url.lastIndexOf("?")); } if (url.lastIndexOf("#") >= 0) { url = url.substring(0, url.lastIndexOf("#")); } menu_url = url; var main = document.getElementById(menu_id); if (!main) alert("No element with id '"+ menu_id +"' found"); menu_traverse(main); } /* Walks down the subtree and on the way back sets properties. returns bit set 1: set = element is a node, unset = element is a leaf 2: set = element contains the active node 4: set = element is the active A node */ function menu_traverse(element) { var props = 0; // walk down for (var i=0; i<element.childNodes.length; i++) { var child = element.childNodes[i]; props |= menu_traverse(child); // aggregate bits } // on the way back now switch (element.tagName) { case "UL": props |= 1; break; case "LI": var c1 = (props & 1) ? ((props & (2|4)) ? menu_open_class : menu_closed_class) : menu_leaf_class; element.className = element.className ? element.className+" "+c1 : c1; if (props & 4) { if (!(props & 2)) element.className += " "+menu_active_class; props |= 2; props &= 1 | 2; // reset bit 4 } break; case "A": if (props & 2) break; // once is enough var href = element.getAttribute("href"); if (menu_isSameUrl(menu_url, href)) props |= 4; break; } return props; } //matches two URIs when href is the last part of url //.. and . are correctly resolved function menu_isSameUrl(url, href) { var a = url.split(/[?\/]/i); var b = href.split(/[?\/]/i); var i = a.length - 1; var j = b.length - 1; while ((i >= 0) && (j >= 0)) { if (b[j] == "..") { j-=2; continue; } if (a[i] == "..") { i-=2; continue; } if ((b[j] == ".") || (b[j] == "")) { j--; continue; } if ((a[i] == ".") || (a[i] == "")) { i--; continue; } if (! (a[i] == b[j])) return false; i--; j--; } return true; } New to this forum but hope this will explain my problem, any help is much appreciated! thanks!! Jesper I want to make a script that will insert all text type inputs into an array. From there I want to be able to call them and edit them. Here is what I have so far and it is not working. var phone1 = '702' var inputArray = new Array(); var inputs = document.getElementsByTagName('input'); inputs; if (input.type == 'text') { inputArray.push(inputs.id); } inputArray.reverse(); inputArray[0].value = phone1; I know you can add data to array wiht the push() method but can you add a whole new line as in a = new Array a [1] [1,2,3] so it would create a new line a [2] [4,5,6]; The syntax to the array i think is wrong but you get the question. Okay so im just doing a little test and this might seem like a really stupid question but i cant figure it out...all i simply want to do is take all those numbers and get the sum then display the sum in a document.write in theory i should get 10 but i dont and idk why i have tried many many things Code: var numbers = new Array(); numbers[0] = 1; numbers[1] = 2; numbers[2] = 3; numbers[3] = 4; thanks Resolution: Code: <script type="text/javascript"> function amountTotal() { var totalDonations = 0; for (var i = 0; i < amount.length; i++) { totalDonations += amount[i]; } document.write(totalDonations); } </script> I have an array in a seperate.js file that I need to step through a FOR loop to grab all these values and add them together. Here is a small sample of the array's: Code: city = new Array(); state= new Array(); zip = new Array(); amount = new Array(); date = new Array() firstName[0]="Nina"; lastName[0]="Largent"; street[0]="88 Regal Lane"; city[0]="Williamsburg"; state[0]="KY"; zip[0]="40769"; amount[0]=125; date[0]="2011-09-18"; firstName[1]="Mike"; lastName[1]="Hart"; street[1]="Da404 Barrow Street"; city[1]="London"; state[1]="KY"; zip[1]="40744"; amount[1]=75; date[1]="2011-09-18"; Here is the loop step through that I have: Code: <script src="arrays.js" type="text/javascript"></script> <script type ="text/javascript"> function amountTotal() var totalDonations = 0 for (var i=0; i < amount.length; i++) { } </script> I am stuck on how to grab each amount index and add them together to save them as the amountTotal variable. Years ago I created HTML that employs checkboxes and textboxes. I am now writing JS with the intention of adding flexibility and limiting redundancy. I am not sure I truly understand how to correctly interact the two though. For example, one of my scripts have arrays that contain the names of the checkboxes and textboxes, with a 'for' loop to document.write() them to references within the HTML code. This does not seem to be working for me though. Here is what I have thus far (in short): Code: <script language="javascript"> var teamNames = new Array(3); teamNames[0]="South Africa"; teamNames[1]="Mexico"; teamNames[2]="Uruguay"; for (i=0; i<=31; i++) { document.write("<p>" + teamNames[i] + "<\/p>"); } </script> </head> <body> <tr><td>Jun 11</td><td><input type="checkbox" name="teamNames[0]" value="teamAbbr[0]"></td> </body> I've left out a lot of the code (to include the teamAbbr array, but you get the points. I've tried moving the JS within the HTML body and playing with the reference syntax, but nothing so far. Any help would be great! I've got this little chunk of code running on my freelance portfolio site - on each page (different sections of my portfolio) I have 6 thumbnails and a full sized graphic with some descriptive info, you click the thumbnail and it switches the graphic and other info, that all works fine. But on one page I have some web stuff and I'd like to make the var 'clientinfo' into a link to go to the client's website. I know I need to add an array with the website links, but then I'm not sure how to implement it into the html, I've tried various things I've found on here but I'm not getting anywhere on my own. I know it's something pretty simple (for someone who knows what they're doing) but I just can't seem to grasp it. Can anyone help? the js is like this: $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var title = $(this).attr("title"); var description = $(this).attr("content"); var clientinfo = $(this).attr("clientinfo"); $('#gallery').hide(); $('#gallery').fadeIn('slow'); $('#image').html('<img src="' + image + '"/>'); $('#title').html(title); $('#description').html(description); $('#client').html(clientinfo); return false; }); and then the HTML anchors are like this: <a href="#" rel="images/gallery/web/site1.png" title="Site One" content="This is the descriptive info for site number one" clientinfo="Site One link" class="image"><img src="images/gallery/web/t_site1thumb.png" class="thumb" border="0"/></a> Can anyone help me set coordinates for an image I want to add to my page? I have the center coords where I want it to be places x is 400 and y is 90. I've searched all over the internet trying to find a solution.
Hey guys/gals, do ya know an efficient way to get the coordinates of a pictures so that I can use them to create a map? It is a rectangle. Here is the code I set up for a page: Code: <HTML> <HEAD> <TITLE>Cyrus</TITLE> </HEAD> <BODY BGCOLOR=black> <div align="center"> <table border="0"; cellspacing="0"; cellpadding="0"> <tr> <td><img src="http://i732.photobucket.com/albums/ww329/Chrishick/pageheadername.png"; width=900px; hieght=160px;></td> </tr> <tr> <td><img src="http://i732.photobucket.com/albums/ww329/Chrishick/navbar.png" width=900px; border="none" usemap="#navbar"></td> </tr> <tr> <td> <br> <br> <table border="0"; width=900px> <tr> <td> <div align="left"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/appearance-2.png"; width=466px; hieght=320px></div> </td> <td> <div align="right"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/equipment.png"> <br><br> <img src="http://i732.photobucket.com/albums/ww329/Chrishick/personality.png"> </div> </td> </tr> </table> </td> </tr> <tr> <td></td> </tr> <tr> <td> <div align="center"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/brought.png"></div></td> </tr> </table> </div> <map name="navbar"> <area shape="rect" coords="247,185,445,220" href="http://www.roleplayandwritinghaven.com/forum.htm" alt="Forum" /> </map> </BODY> </HTML> i have a javascript running on my web page, however the text in the input field is white, on a white background. making it unreadable. is there a way to change the text color for the script. site can be viewed he www.barren-county.net the script running is the toolbar at the bottom, more specifically the "Connect" app on the right, if you open it you see that the text field is white and text is invisible. here is the code i have: Code: <head> {S_HEADER_TAGS} <link rel="stylesheet" type="text/css" href="{THEME_PATH}/style/style.css" /> <!-- IF S_MAIN_MENU or S_ADMIN_CSSMENU --> <link rel="stylesheet" type="text/css" href="{THEME_PATH}/style/cpgmm.css" /> <!-- ENDIF --> {CSS_IE} <script src="http://cdn.wibiya.com/Toolbars/dir_0585/Toolbar_585555/Loader_585555.js" type="text/javascript"></script> </head> <body> can you help? Hi, Looking for some help with something, I have a table with 20 columns, Im looking to color code column 7,8,9,10,11,12. all of the data is numeric. Here is how they should be colored. column 7 (column header name is test7) if >50 should be red if 41-50 should be yellow if <=40 should be green column 8 (column header name is test8) > 40 should be red 32-40 should be yellow <=31 should be green this is similiar for other colums, if someone could help with this one I could figure out rest. thanks jay |