JavaScript - Changing Color Of Cell Based On Number Of Clicks
Hi all,
I currently have this javascript that will change the cell to green with one click... Code: <script type="text/javascript"> function ColorChange(obj){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#66CC33'; obj.parentNode.style.backgroundColor='#66CC33'; } </script> echo "<td align=\"center\" bgcolor=\"#EEEEEE\"><a href=\"#\" onclick=\"ColorChange(this)\">$day_num</a></td>"; the problem is that I need around 3 different colors to be possible.. e.g. 1 click turns cell green | 2 turns is red | 3 turns it orange. I'm not sure how to take this javascript further? Would someone be kind enough to point me in the right direction? Many thanks, Greens85 Similar Tutorials<script language="JavaScript"> function changeColor(cell_id){var state1="#dde6ed"; var state2="#ffc20e"; var cellid = new Array ("id1", "id2", "id3", "id4", "id5", "id6"); for(var i = 0; i < cellid.length; i++){var nav = document.getElementById(cellid[i]); if(cellid == nav.id){nav.style.backgroundColor=state2;} else {nav.style.backgroundColor=state1;}}} </script> Can anyone tell me what is wrong with this script. I put an onClick= changeColor(this);" in my <td> tag to call the script but still not working. Hi, First, I'm a newbie in javascript and I need help to do something with a random numbers. I would like to put the result numbers in the "<td class="style1">#01</td>" section and an image in <td class="style1">img1</td> depending of the result number. Exemple : If the result number is #1 then the image Under the #01 will be an image associated to the number 1". Number 1 = "red circle.jpg", Number2 = "blue square.jpg", etc. Am I clear ? Here is my actual HTML canvas : -------------------------------------- <!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>Result</title> <style type="text/css"> .a1{ position:relative; font-family:Verdana; font-size:20px; color:#888888; } .style1 { text-align: center; } </style> <script language="JavaScript"> /***************************************** * Lottery Picker (By Kurt at kurt.grigg@virgin.net) * Featured on/available at Dynamic Drive DHTML(dynamic html) & JavaScript code library * Modified by DynamicDrive.com for below config options * This notice must stay intact for use. *****************************************/ var totalnumbers=6 //input total numbers to generate var lowerbound=1 //input lower bound for each random number var upperbound=49 //input upper bound for each random number function lotto(){ B=' '; LottoNumbers=new Array(); for (i = 1; i <= totalnumbers; i++) { RandomNumber = Math.round(lowerbound+Math.random()*(upperbound-lowerbound)); for (j = 1; j <= totalnumbers; j) { if (RandomNumber == LottoNumbers[j]) { RandomNumber=Math.round(lowerbound+Math.random()*(upperbound-lowerbound)); j=0; } j++; } LottoNumbers[i]=RandomNumber; } LottoNumbers=LottoNumbers.toString(); X=LottoNumbers.split(','); for (i=0; i < X.length; i++) { X[i]=X[i]+' '; if (X[i].length==2) X[i]='0'+X[i]; } X=X.sort(); for (i=0; i < X.length; i++) { OutPut=B+=X[i]; } if (document.all)document.all.layer1.innerHTML=OutPut; if (document.getElementById)document.getElementById("layer1").innerHTML=OutPut; if (document.layers){ document.layers.layer1.document.open(); document.layers.layer1.document.write("<span style='position:absolute;top:0px;left:0px;font-family:Verdana;font-size:20px;color:#888888;text-align:center'> "+OutPut+"</span>"); document.layers.layer1.document.close(); } T=setTimeout('lotto()',20); //window.status=OutPut; } function StOp(){ setTimeout('clearTimeout(T)',1000); } //--> </script> </head> <body> <table border='0' width=250 style="height: 146px"> <tr valign='middle'> <td align='center'> <form name=form> <input type=button value='Lottery Number Picker' onClick="lotto();StOp()"> </form> <span id=layer1 class=a1>Result</span> </td> </tr> </table> <table style="width: 250px; height: 100px" cellspacing="0" cellpadding="0"> <tr> <td class="style1">#01</td> //result number 1 have to be here <td class="style1">#02</td> //result number 2have to be here <td class="style1">#03</td> //result number 3 have to be here <td class="style1">#04</td> //result number 4 have to be here <td class="style1">#05</td> //result number 5 have to be here <td class="style1">#05</td> //result number 6 have to be here <td style="height: 50px" class="style1">#06</td> </tr> <tr> <td class="style1">img1</td> //associated image of the result number 1 have to be here <td class="style1">img2</td> //associated image of the result number 2 have to be here <td class="style1">img3</td>//associated image of the result number 3 have to be here <td class="style1">img4</td>//associated image of the result number 4 have to be here <td class="style1">img5</td>//associated image of the result number 5 have to be here <td class="style1">img6</td>//associated image of the result number 6 have to be here </tr> </table> </body> </html> -------------------------------------- Thank you very much to helping me to understand how to do it !! Sylvano Reply With Quote 12-22-2014, 05:36 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts This is hideously old and indeed crude code. document.all applied to IE4 and document.layers to Netscape 3. <script language="JavaScript"> and document.write() are also long obsolete. As is T=setTimeout('lotto()',20); I would suggest you get hold of a more up-to-date code. Simply rename your images 1.jpg, 2.jpg and so on, and display the appropriate one in its correct position. I'll give you a far better lottery number generator:- Code: <!DOCTYPE html> <head> </head> <body> <script type = "text/javascript"> function mylotto() { var rlts = document.getElementById("results"); rlts.value = ''; // clear results var srtrlts = document.getElementById("sortedresults"); srtrlts.value = ''; // clear results var hmany = document.getElementById("howmany").value; var max = parseInt(document.getElementById("maxnum").value); if (isNaN(max) || max <= hmany) { alert ("You must choose a number greater than " + hmany + " for the maximum number value!"); document.getElementById("maxnum").value = 49; return false; } var numArray = new Array(max); var chosen = new Array(hmany); var uniqueList = new Array(hmany); for (var i = 1; i <= max; i++) { // set up array 1 to max numArray[i-1] = i; } Array.prototype.shuffle = function() { var s = []; while (this.length) s.push(this.splice(Math.random() * this.length, 1)); while (s.length) this.push(s.pop()); return this; } numArray.shuffle(); // shuffle the array for (var i = 0; i < hmany; i++) { // take the first howmany items uniqueList[i] = numArray[i]; } rlts.value = uniqueList.join(" "); srtrlts.value = uniqueList.sort(sortNumber).join(" "); function sortNumber(a,b) { return a - b; } //alert ("The unsorted random numbers a - \n" + uniqueList) //alert ("The sorted unique random numbers a - \n" + uniqueList.sort(sortNumber)); } </script> <p>UNIQUE NUMBERS LOTTERY PICKER</p><br> <form> Select How Many Unique Numbers <select id="howmany"> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> <option value=4>4</option> <option value=5>5</option> <option value=6 selected>6</option> <option value=7>7</option> <option value=8>8</option> <option value=9>9</option> <option value=10>10</option> </select> <br> Enter the Maximum Number Value  <input type="text" id = "maxnum" value="49" size="2"><br><br> <input type="button" value="Here we go!" onclick="mylotto()"> <br><br> Unsorted Results:- <input type = "text" id = "results" size = "60"><br> Sorted Results:-     <input type = "text" id = "sortedresults" size = "60"> </form> </body> </html> Quizmaster: In which river did John the Baptist baptise Jesus? Contestant: The Amazon Hello, Can someone please show me how to do the following in Javascript. I basically want the background color of a div (banner) to change when the user clicks a green or blue table cell. So if they click the blue table cell, the backgound color of the div changes to blue (its green by default). Also, when they have picked what color they want, I'd like the color to be stored in the value of the form 'BannerBGColor' so I can post their banner color to database. Any help is greatly appreciated. Many thanks -------------------------------------------------------------------------- Banner: <div style="width:400px; float:center; background:#00FF00; border-color:#000000; border-style: solid; border-width: 2px;"> <p>This is a banner.</p></div>'; -------------------------------------------------------------------------- Colour picker table to change colour of Banner above: <table width="300" border="1" cellspacing="1" cellpadding="1"> <tr> <td colspan="2">Pick a color below to change banner background:</td> </tr> <tr> <td bgcolor="#00FF00">Green</td> <td bgcolor="#00FFFF">Blue</td> </tr> </table> ------------------------------------------------------------------------- Form field to insert chosen Banner Background colour when form is submitted - <input type="text" name="BannerBGColor" value="'.$_POST['BannerBGColor'].'"> Hi, I have a php script that displays database data in a web table. I also have a javascript code which is supposed to compare the value entered in a web form to that hard coded in the script and change the color to green if its below, amber if its equal and red if its greater than. Below is my javascript code: Code: <script type="text/javascript"> function hallo(){ var value1=200 var inputVal = window.document.getElementById("one").value; //alert(negNum); if(inputVal > value1){ window.document.getElementById("color").style.color="red"; } else if(inputVal < value1) { window.document.getElementById("color").style.color="green"; } else if(inputVal == value1) { window.document.getElementById("color").style.color="#FF7E00"; } } </script> And below is my php script that displays the data in a web table. Code: <body> <form> Value1: <input type="text" name="one" id="one" ><br/> Value2: <input type="text" name="two" id="two" value="" onClick="hallo();"> <br/> Value3: <input type="text" name="three" id="$cell" value="test data"> </form> <?php require_once("database.php"); $CustID=$_POST['CustomerID']; $query="SELECT c.*,r.Meter_No,r.January,r.February,r.March,r.April,r.May,r.June FROM customer AS c,readings AS r WHERE c.CustomerID=r.CustomerID AND c.CustomerID='".$CustID."'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">CustomerID</font></th> <th><font face="Arial, Helvetica, sans-serif">Title</font></th> <th><font face="Arial, Helvetica, sans-serif">First_Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Last_Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Meter_No</font></th> <th><font face="Arial, Helvetica, sans-serif">January</font></th> <th><font face="Arial, Helvetica, sans-serif">February</font></th> <th><font face="Arial, Helvetica, sans-serif">March</font></th> <th><font face="Arial, Helvetica, sans-serif">April</font></th> <th><font face="Arial, Helvetica, sans-serif">May</font></th> <th><font face="Arial, Helvetica, sans-serif">June</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"CustomerID"); $f2=mysql_result($result,$i,"Title"); $f3=mysql_result($result,$i,"First_Name"); $f4=mysql_result($result,$i,"Last_Name"); $f5=mysql_result($result,$i,"Meter_No"); $f6=mysql_result($result,$i,"January"); $f7=mysql_result($result,$i,"February"); $f8=mysql_result($result,$i,"March"); $f9=mysql_result($result,$i,"April"); $f10=mysql_result($result,$i,"May"); $f11=mysql_result($result,$i,"June"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f9; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f10; ?></font></td> <td id="color"><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td> </tr> <?php $i++; } ?> </body> As you can see from my javascript, i am getting the elements by id (getElementById("color")). Currently, only the first <td> with id='color' is changing when the value is entered. How do I make the text in other table cells with id='color' change color when the comparison value is entered? I am working on a project where I have 5 XML files that I bring into HTML and display the tables on one browser page. I would like for the row of the tables to change depending on what is in the "status" field. There will only be the following inputs in that column - "IS" which is in stock(green), "OS" which is out of stock(red), and "PO" which is Pre-Order(blue). 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>ABC Book Store</title> <style type="text/css"> <!-- .style1 { font-size: 10pt; } --> </style> <script> function ld_fiction() { var doc=nb_fiction.XMLDocument; doc.load("fiction.xml"); document.getElementById("head_id").innerHTML="Fiction "; } function Id_nfiction() { var doc_s=nb_nfiction.XMLDocument; doc_s.load("nfiction.xml"); document.getElementByID("head_id_d").innerHTML="NonFiction"; } function ID_selfhelp() { var doc_t=nb_selfhelp.XMLDocument; doc_t.load("selfhelp.xml"); document.getElementByID("head_id_e").innerHTML="SelfHelp"; } function ID_reference() { var doc_u=nb_ref.XMLDocument; doc_u.load("ref.xml"); document.getElementByID("head_id_f").innerHTML="Reference"; } function ID_mags() { var doc_v=nb_mags.XMLDocument; doc_v.load("mags.xml"); document.getElementByID("head_id_g").innerHTML="Mags"; } </script> <XML id="nb_fiction" src="fiction.xml"></XML> <XML id="nb_nfiction" src="nfiction.xml"></XML> <XML id="nb_selfhelp" src="selfhelp.xml"></XML> <XML id="nb_ref" src="ref.xml"></XML> <XML id="nb_mags" src="mags.xml"></XML> <object id="nb_fiction" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" height="0"></object> <object id="nb_nfiction" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" height="0"></object> <object id="nb_selfhelp" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" height="0"></object> <object id="nb_ref" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" height="0"></object> <object id="nb_mags" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" width="0" height="0"></object> <body> <table width="30%" border="0" align="left" cellspacing="1" font size="10"> <tr bgcolor="#CCCCCC"> <td colspan="2"> <table id="FICTIONTABLE" table width="100%" datasrc="#nb_fiction" font size="1" border="0" align="center" bordercolor="#FFFFFF"> <caption> <span>Fiction </span> </caption> <thead> <tr> <th span class="style1">Stock No.</th></span> <th span class="style1">Title</th></span> <th span class="style1">Author</th></span> <th span class="style1">Status</th></span> <th span class="style1">Price</th></span> <th span class="style1">Publisher</th></span> <th span class="style1">Year of Release</th></span> </tr> </thead> <tbody> <tr> <td><span class="style1" datafld="stock"></td></span> <td><span class="style1" datafld="title"></td></span> <td><span class="style1" datafld="author"></td></td></span> <td><span class="style1" datafld="status"></td></span> <td><span class="style1" datafld="price"></td></span> <td><span class="style1" datafld="publisher"></td></span> <td><span class="style1" datafld="year"></td></span> </tr> </tbody> </table> </td> </tr> </body> </html> I only included the first part of the html code along with the first table, but there is a table for each xml file. You can also probably tell how the XML files are structured by looking at the way they are displayed in the tables. I think what I want to do can be accomplished with JavaScript, but I have no idea how to do it and it's the only thing I have left before I'm done. Any help would really be appreciated and thanks in advance. Hi friends, What I have been trying to achieve is, On my index.htm, I have a horizontal cell named "memberarea" which originally shows username & password input fields. After the user logs in, this area changes itself to a "Welcome Name, Lastname" field. I want that this cell displays again the username and password input fields in case of the session of the user has expired. I have tried it with the following code (within the Iframe in index.htm): ----------------------------------------- <script> if ("<%=session("LoginFirstName")%>" == "") { var m = " <p align="center"> <font style="font-size: 8pt; font-weight: 700" face="arial"> Username:</font> <span style="font-size: 1pt"> <input type="text" name="uid" id="uid" size="14" style="width: 65; height: 17; font-size: 8pt"></span><font face="arial" style="font-size: 8pt"> </font><font style="font-size: 8pt; font-weight: 700" face="arial">Password:</font><font face="arial" style="font-size: 8pt"> </font><span style="font-size: 1pt"> <input type="password" name="pwd" id="pwd" maxlength="10" size="14" style="width: 65; height: 17; font-size: 8pt"></span><span style="font-size: 1px"> </span> <input type="submit" value="Enter" name="B1" style="width: 35; height: 17; font-size:9px" onclick="return login()">"; window.parent.document.getElementById('memberarea').innerHTML=m; } </script> -------------------------------------------------- This code gives me the error that on the 12xx'the line (which does not exist-the whole code is 5xx lines). there is a ";" missing which I could not found. Any ideas how to achieve this? Thank you for your comments I have a table that has 20 or so columns. The last 5 columns need to be color coded. The numbers will be populated in those columns, and for example.. column 1 = (for any field in this column) >50 red 45-50 yellow <=40 green each of the last 5 columsn have to be like this except with different numbers. can someone help with this ? Hello, I can't seem, for the life of me to get this to work at all. I've tried everything out there and can't get it to work with IE 7: I would like to change the border color of my table row on hover. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test</title> <style type="text/css"> .test { border:1px solid #9CA4AA } .test:hover { border:1px solid #666666 } </style> </head> <body> <table width="536" style="border:1px solid #9CA4AA" cellspacing="0" cellpadding="1"> <tr class="test"> <td> </td> </tr> </table> </body> </html> I desperately need your help before I have no hair left. Thanks for all your help in advance, Cheers, J So my functions are dealing with Time. The function delay_time() is called by clicking a button in html and the return value of the function is displayed in a textbox. What I need to do is basically if the value of resultingtime is greater that the value of delay time I need the value shown in red(ff0000) and bold and if it isnt then I need it displayed in bold green(00ff00). but Ive tried doing this in my javascript and found that I cant code it in there the way that I know. I really dont know what to do... I think that I have to do it in the html coding but I dont know how. Here is the javascript I wrote: Code: function delay_time(idealTime, startTime, stopTime, delayTime) { var delay_time = idealTime.value; var bigger_time = stopTime.value; var smaller_time = startTime.value; var resultingtime = subtract_time(bigger_time, smaller_time, delay_time); //if (resultingtime > delay_time) { //resultingtime = resultingtime.fontcolor("ff2000"); //resultingtime = resultingtime.bold(); //} //else { //resultingtime = resultingtime.fontcolor("60ff00"); //resultingtime = resultingtime.bold(); //} delayTime.value = resultingtime; } function subtract_time(bigger_time, smaller_time, delay_time) { var bigger_value = convert_time_to_value(bigger_time); var smaller_value = convert_time_to_value(smaller_time); var idealTime = delay_time; var resultingtime = bigger_value - smaller_value; return resultingtime; } function convert_time_to_value(time_format) { var hh = time_format.substring(0, 2); var mm = time_format.substring(3, 5); var time_value = (eval(hh) * 60) + (eval(mm) * 1); return time_value; } and here is the html code for the button : Code: ID="Button15" type="button" value="Delay Time" onclick="delay_time(document.getElementById('TextBox102'), document.getElementById('TextBox104'), document.getElementById('TextBox105'), document.getElementById('TextBox106'))"/> here is the text box I have the value going into: Code: <asp:TextBox ID="TextBox106" runat="server" Height="0.25in" Style="font-family: Arial, Helvetica, sans-serif; font-size: medium" Width="0.75in" BorderStyle="Inset"></asp:TextBox> and here is the code from the box that I need to know if the value is bigger or smaller than: Code: <asp:TextBox ID="TextBox102" runat="server" Height="0.25in" Style="font-family: Arial, Helvetica, sans-serif; font-size: medium; text-align: right;" Width="0.5in" BorderStyle="Inset"></asp:TextBox> please help. Hey everyone! My goal here is to have the user type in a color and have that color display as the background of the page. I don't believe the switch statement is being executed by the first function. I think I am overthinking the process - as always! Any help pointing out my mistake(s) would be greatly appreciated. Code: function show_color() { var show_prompt = prompt("Please enter a color name"); var change_body = document.getElementById("body");; show_prompt = change_body; change_body = change(this.id); } function change(id) { switch (id) { case 'red': document.body.bgColor = "red"; break; case 'green': document.body.bgColor = "green"; break; case 'yellow': document.body.bgColor = "yellow"; break; case 'blue': document.body.bgColor = "blue"; break; case 'pink': document.body.bgColor = "pink"; break; } } Hi guys. I am kind of new to javascript, and was hoping that someone here could help out on a problem I have been having. What I am trying to do is to make a page which will redirect to three diffrent sites, based on date. I want it to change to diffrent sites during the time before summer to summer, the time before xmas till xmas and from before easter till easter. A bit more spesific this would be: From 29. march --> 22. july (summer) From 22. august --> 24. december (xmas) From 3. january --> 22. march (easter) Could you help me out? I have tried lots of diffrent ways to do this with javascripts if...else statements, but I havent yet found a way to make it work properly. Really thankful for answers! hi im trying to make the background color change to white after the iframe is triggered. right now it sits transparent on the page but after the iframe is triggered i want the background to be white. is there a way to do this? i dont know much about java but im assuming this would be something to use java for. Thanks Code: <iframe name="result" style="border: 0px solid #000000;"frameborder="0" width='100%' height='590px' src="result1.php" allowtransparency="true"></iframe> I'm a member of a forum the for the Winter season has changed it's CSS a:link color attribute to a more winter themed colour. However I want to revert back to original as I don't particularly like the new colour. My theory is to create a small JS file, that I can define Opera (my browser) to load when loading the site, which will change the colour of links back to the original colour. I have the colour code HTML I want to change it to. I've only ever done a small amount of JS coding but from the research I've done it should go something like this, Code: document.style.alinkColor = "COLOR" I got to that via discovering that Code: document.style.backgroundColor = "COLOR" will change the background colour attribute, however it doesn't seem to work. I think my problem lies somewhere in the attribute name, I know the usually with JS CSS Attributes you would make the attribute starting with a lower case letter and the sub-attribute (e.g. the color bit) starting with an upper case. Anyone able to point me in the right direction? Hey guys, I have been trying to get better at my javascript as of late and there is this one particular color fading technique I have found that I am having trouble dissecting. The following code appears to be how they are making a rollover go from a dark gray to a subtle light gray with a nice fade but I can't exactly tell whats going on from the code. Is it just telling it to add a rgb point in so many seconds? Any professional help would be greatly appreciated. Code: colorInit= true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],0),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],0),255),0)+")"}}); I want to create a basic script where someone clicks the button and the document color is changing. while I can do it with inline even handlers and also using the script block in html document, i am not able to achieve the result using the external js.js. My goal is not to use any even handlers at all inside the html document. This is how my codes looks like: <head> <title> Basics Exercise</title> <script type="text/javascript" src="js.js"></script> </head> <body> <form> <p> Click this button and the document's color will change again </p> <input name="button" type="button" value="Change the background color of the document"/> </form> js.js has function changecolor() { document.bgColor='#ea0d17'; } document.forms[0].button.onClick=changecolor(); I don't want anyone to write a script for me, but I would appreciate if someone told me why the script I wrote is not working. Hello I want to html text to show diffrent color, if date in list is in the past. shoud this even work ? am i hopeless? Code: <script type="text/javascript"> var day = d.getDay(); var event = this.document.getElementById('list'); if ('day' < 'event') { document.getElementById('list').style.color = '#DB35B0' } </script> <ul> <li id ="list">26/02/12 Some happening here</li> <li id ="list">27/02/12 Some happening here</li> <li id ="list">28/02/12 Some happening here</li> </ul> Is it possible to give an anchor tag an id and call it with GetElement? this is what I have tried: Code: <a id="link1" href="test.html">Part 1</a></li> Code: document.getElementById("link1").style.color = "blue"; This is my CSS: Code: A:link { color:#ffffff; font-size:14pt; font-weight:bold;} A:visited { color:#ffff00; font-size:14pt; font-weight:bold;} A:hover { color:#6698ff; font-size:14pt; font-weight:bold;} A:active { color:#c0c0c0; font-size:14pt; font-weight:bold;} Hi, Is there anyone who could help me figure out how to Change a Hidden Fields Name based on selected option. The hidden fields name is sent off and I need to change the name depending on what option they select. For if they select MyList the hidden field name needs to be SelectLists[40] or if they select testlist the hidden field name needs to be SelectLists[41]. This is probably way, way off but I've done this and it doesn't work. Any help would be greatly appreciated, thanks. <script language="JavaScript"> function changelist() { //here we assign the value of the hidden input to x x=eval(document.getElementByName("SelectLists[40]"); if(document.getElementById("SelectLists[40]").selected=true x=SelectLists[40] else(document.getElementById("SelectLists[41]").selected=true x=SelectLists[41] else(document.getElementById("SelectLists[42]").selected=true x=SelectLists[42] //now we assign the new value to the input document.getElementById("theHiddenInput").name=x; //and now we test alert(document.getElementById("theHiddenInput").name) } </script> <input type="hidden" id="theHiddenInput" name="SelectLists[40]" value="Yes"> <select class="inpBox" style="width: 287px" name='mailinglist' id="lists" onchange="changelist()"> <option value="SelectLists[40]" name="SelectLists[40]" id="SelectLists[40]">MyList</option> <option value="SelectLists[41]" name="SelectLists[41]" id="SelectLists[41]">testlist</option> <option value="SelectLists[42]" name="SelectLists[42]" id="SelectLists[42]">testlist2</option> Need help - sorry for the novice-ness of this. Have a computed field ("Subtotal"). With that number, need to set up rule such that if Subtotal is a certain number, a certain number will print in the new field (lets call it "First"). Here's what I have so far... var a=getField("Subtotal").value; var b=5000; var c=9000; var d=33000; var e=53000; var f=68000; var g=78000; var h=83000; var i=0; Code: if (a.value<=100000){ event.value=b } else if (a.value<=200000 && a>100000){ event.value=c.value } else if (a.value<=1000000 && a>200000){ event.value=d.value } else if (a.value<=2000000 && a>1000000){ event.value=e.value } else if (a.value<=3000000 && a>2000000){ event.value=f.value } else if (a.value<=4000000 && a>3000000){ event.value=g.value } else if (a.value<=5000000 && a>4000000){ event.value=h.value } else if (a.value==0){ event.value=i.value } Any thoughts??? Help is GREATLY appreciated. D Dear all, background information: I did code a timesheet management system for my company with PHP where the user has to submit time entries and has an online form with several start and end times. The start and end times are all simple HTML select option dropdowns. I want that the first End time selection will be the next start time selection. Basically a simple dependency of the dropdown. My approach was that I want to solve this with JavaScript. In my php code I am echoing the following (in this select the end times are the values): echo "<select class='normal' name='$field_id' onChange=set_time_hour(this.value,'$field_id_js')>"; When the user changes then the end time dropdown the next field (next start time entry) should be changed accordingly. The javascript looks like this function set_time_hour(hour_value,next_field){ alert (hour_value); alert (next_field); document.getElementById(next_field).value = hour_value; } The alert calls are giving me the right values. but the document.getElementById(next_field).value = hour_value; is not working. What is wrong there? Do you have an idea? How can I change the value of a select box with Javascript? The select box values are already popoluated with PHP so I just want to select the right value. |