JavaScript - Dropdown Update
Similar TutorialsHi, I want to recreate the effect of the drop-down bar that appears at the top of your browser when prompted to download an updated version of flash. Its for a proprietory plugin, but can't seem to get anywhere with it... Anyone have any ideas? Hi, I'm trying to integrate an address finder (http://www.craftyclicks.co.uk/) into my shopping cart (OsCommerce). I can get it to work but I need to add my own functionality. I'm not very experienced with JavaScript and my head has entered an infinite loop by now. The problem is that the address finder script can change the selected country in a drop-down list depending on the postcode entered by the user (using the onblur event handler). What I need it to do is to remove all other countries depending on the postcode. I can get it to remove all other countries but how do i return to the original list of countries when the postcode is changed again? Once all other counties are removed, the drop-down list will obviously only have one option left... I guess the question is also how does a function remember what it has done before, when it is called again? I have written this short test script as it is easier to work with than the craftyclicks oscommerce contribution: 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>HTML Template</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <script type="text/javascript"> //<![CDATA[ function store(element) { // store values var cl = element; var text_list = new Array(); var value_list = new Array(); var length = cl.length; for (var foo=0; foo<length; foo++) { text_list[foo] = cl.options[foo].text; value_list[foo] = cl.options[foo].value; alert("text array " + foo + " " + text_list[foo]); alert("value array " + foo + " " + value_list[foo]); } populate(cl, text_list, value_list); } function populate(element, text, value) { // populate options with previously stored values var cl = element; var length = cl.length; cl.options.length=0; for (var bar=0; bar<length; bar++) { cl.options[bar]= new Option(text[bar], value[bar], false, false); } } function crafty_set_country(code) { var cl = document.getElementById('select'); store(cl); for (var i=0; i<cl.length; i++) { if (cl.options[i].value == code) { alert(cl.options[i].value + " found"); var value = cl.options[i].value; var text = cl.options[i].text; cl.options.length=0; cl.options[0]=new Option(text, value, true, true); /* for (var j=0; j<cl.length; j++) { alert("second loop " + cl.options[j].text); if (cl.options[i].value != code) { cl.options[j] } } */ } else { alert(cl.options[i].value); } } } //]]> </script> </head> <body> <form> <select id="select"> <option value="10">ten</option> <option value="20">twenty</option> <option value="30">thirty</option> <option value="40">fourty</option> <option value="50">fifty</option> <option value="60">sixty</option> </select> <input type="button" value="remove" name="button" onClick="crafty_set_country(50)"> <input type="button" value="repopulate" name="button" onClick="crafty_set_country(100)"> </form> </body> </html> Many thanks! Martin hey guys The first dropdown has some options as : abc(a) bcd(a) cde(b) def(b) efg(c) fgh(c) The second dropdown has : a b c On selecting abc(a) in first dropdown the 'a' must get selected in second dropdown,on selecting cde(b) second dropdown must have 'b' and so on,also the second dropdown value should be disabled(grayed out) for user.Need the code in javascript.ty in advance. Hello, I am completely new to HTML/JS/CSS, therefore I know very little. I have two drop-down prompt controls with month names. One has just one value (say "July") and the other has all the months of the year ("January".."December"). The first prompt control is hidden on the page. How do I set the default selection of the second prompt control to the value present in the first prompt control? So, when the page is run, the second prompt control should automatically show "July". I was reading up on the selectedIndex property (?), but I know that it won't work because I want Index 0 to be selected in the first control and Index 6 in the second, and I expect it to change every month (next month it will be index 7 that should be automatically selected). If it matters, I am using IE8. Thanks! Hi, I have two dropdown lists with the second one being dependent on the selection in the first. Options in list 1: 1,3 or 4 List two should be enabled when 3 or 4 is selected in list 1. So far so good, managed to get it to work with only one set of lists, but I actually have 18 of those sets in this form: Code: <select name="fw[$i]" id="fw[$i]"> <option value="1">FWH</option> <option value="3">links</option> <option value="4">rechts</option> <option value="0" selected></option> </select><br /> <select name="lie[$i]" id="lie[$i]" disabled="disabled" onchange="showBox($i,xxx);"> <option value="0" selected>---</option> <option value="1">gut</option> <option value="2">schlecht</option> <option value="3">Strafschlag</option> <option value="4">OB</option> </select> $i is my index generated by my PHP script and runs from 1 to 18. Everything works just fine as long as the index is not in play. With the index my function breaks, most probably due to my inability to extract the second parameter (xxx above) from the selection field. Here's my function, there could be something wrong there too with how exactly to specify the proper dropdown list to enable. Code: function showBox(field,val) { if (val > 1) { var box = 'lie[' + field + ']'; document.form1.box.disabled == false; } else { document.form1.box.disabled == true; } } Finally, I'm not that adept in javascript programming, more like a trial and error guy, how has hit the wall with this problem. Thanks in advance! Joe if I had two dropdown boxes... If I select the first one with the value of the month name .. eg.. January. How can I get the second dropdown box below to get that same value.?? Thanks S. I am just learning but this is driving me nuts. Any help would be appreciated. I am trying to change the value of a quantity dropdown on this page: http://www.walmart.com/ip/Energizer-...Pack/872068#rr This will change it in the browser but the 3 value is not retained when I add the item to cart. Do I have to do something with onchange? What? Code: document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].value= 3 if i press any key from keyboard all related word to that alphabet will display below the dropdown.what is the code for it.thanks.
Okay well here is my code. i want to mkae it so the functions add together to get a total price, i need some help Code: <html> <head> </head> <script type="text/javascript"> function addit(){ if(document.getElementById("add").value=="0") { document.getElementById("amount").value="$0.00" } if(document.getElementById("add").value=="1") { document.getElementById("amount").value="$5.00" } if(document.getElementById("add").value=="2") { document.getElementById("amount").value="$10.00" } if(document.getElementById("add").value=="3") { document.getElementById("amount").value="$15.00" } } function addit2(){ if(document.getElementById("add2").value=="4") { document.getElementById("amount").value="$30.00" } if(document.getElementById("add2").value=="5") { document.getElementById("amount").value="$40.00" } } </script> <body> <table class="comparison pricing-email" border="0" cellspacing="1" cellpadding="0" width="30%"> <tbody> <tr class="row1"> <td class="col1">Choose # of EMAIL accounts: <select style="width: 60px; font-size: 17px;" name="add" id="add" onChange="addit()"> <option value="0"> </option> <option value="1">1</option> <option value="2">3</option> <option value="3">6</option> </select> </td> </tr> <tr class="row2"> <td class="col2">Choose # of EMAIL accounts: <select style="width: 60px; font-size: 17px;" name="add" id="add2" onChange="addit2()"> <option value="0"> </option> <option value="4">44</option> <option value="5">43</option> <option value="3">342</option> </select> </td> </tr> <tr class="row1"> <td class="col1">Total Price: <input type="text" id="amount" value="" style="border:none; font-size:13pt;"></td> </tr><tr> <td> <input type="submit" name="submit" value="Sign-Up"> </td> </tr> </tbody> </table> </form> </body> Hi All, I have a web camera stream which exports JPG which are over written (ie; 5 jpg's) looping. I'm streaming this feed however, setInterval - refreshImage, 1000 is not lining up with the streaming feed. Is there a way to update the latest jpg image without using setInterval times. I find that depending on the server the timing can be off, and it overlaps or goes too fast. This is my code. Code: <html> <head> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <META HTTP-EQUIV="Refresh" CONTENT="120;URL=http://www.website.com.au"> <?php $time = date('G'); //24 hour without leading zeroes if($time >= 1 && $time <= 6) $loc = 'index.php'; else if($time >= 10 && $time <= 17) $loc = 'index2.php'; else if($time >= 21 && $time <= 24) $loc = 'index3.php'; if(isset($loc)) { header("Location: http://www.website.com.au/{$loc}"); exit; } ?> <script type="text/javascript"> var mypics = []; mypics[0] = 'images/1.jpg'; mypics[1] = 'images/2.jpg'; mypics[2] = 'images/3.jpg'; mypics[3] = 'images/4.jpg'; mypics[4] = 'images/5.jpg'; var image; var imageNum = 0; window.onload = function() { image = document.getElementById('idofyourimage'); setInterval("refreshImage()", 1000); } function refreshImage() { image.src = mypics[imageNum++] + '?' + (new Date()).getTime(); if (imageNum == mypics.length) imageNum = 0; } </script> </head> <body> <script type="text/javascript" language="javascript"> <!-- document.oncontextmenu = function () {return false;}; function do_err() { return true } onerror=do_err; function no_cp() { clipboardData.clearData();setTimeout("no_cp()",100) } no_cp(); //--> </script> <img src="images/1.jpg"; id="idofyourimage" width="640" height="360"/> </body> Thanks !!! Can someone please explain this code to me please. Its the beginning of a javascript code to hide and show a drop down menu. Ill include the html code to give u a better understanding too. Thank you so much, ive been frustrated on this for nearly a month HTML Code: <body> <h1>Menu Test</h1> <ul id=”menu”> <li class=”menu”><a href=”#”>Home</a></li> <li class=”menu”><a href=”#”>Products</a> <ul> <li><a href=”#”>Sub-item 1</a></li> <li><a href=”#”>Sub-item 2</a></li> <li><a href=”#”>Item 3</a></li> </ul></li> <li class=”menu”><a href=”#”>Support</a> <ul> <li><a href=”#”>Sub-item 1</a></li> <li><a href=”#”>Sub-item 2</a></li> </ul></li> <li class=”menu”><a href=”#”>Employment</a> <ul> <li><a href=”#”>Sub-item 1</a></li> <li><a href=”#”>Sub-item 2</a></li> </ul></li> <li class=”menu”><a href=”#”>Contact Us</a> <ul> <li><a href=”#”>Sub-item 1</a></li> <li><a href=”#”>Sub-item 2</a></li> </ul></li> </ul> </body> JavaScript Code: // global variables for timeout and for current menu var t=false,current; function SetupMenu() { if (!document.getElementsByTagName) return; items=document.getElementsByTagName(“li”); for (i=0; i<items.length; i++) { if (items[i].className != “menu”) continue; //set up event handlers thelink=findChild(items[i],”A”); thelink.onmouseover=ShowMenu; thelink.onmouseout=StartTimer; //is there a submenu? if (ul=findChild(items[i],”UL”)) { ul.style.display=”none”; for (j=0; j<ul.childNodes.length; j++) { ul.childNodes[j].onmouseover=ResetTimer; ul.childNodes[j].onmouseout=StartTimer; } } } } // find the first child object of a particular type function findChild(obj,tag) { cn = obj.childNodes; for (k=0; k<cn.length; k++) { if (cn[k].nodeName==tag) return cn[k]; } return false; } Hi, I want to set a different value for each name and use url for values. Can somebody help me with this? eg: name A3 and value http://www.audi.com Code: <script type="text/javascript"> function dynamic1(parent,child){ var parent_array = new Array(); parent_array[''] = ['Please select a manufacturer']; parent_array['Audi'] = ['A3','A4','A5','A6','A8','Q5','Q7','S3','S4','S5','S6','S8','RS6']; parent_array['Dacia'] = ['Sandero','Logan']; parent_array['FIAT'] = ['Bravo','Punto','Grande Punto']; parent_array['Peugeot'] = ['207','308','407','607']; parent_array['SEAT'] = ['Ibiza','New Ibiza','Leon']; parent_array['Skoda'] = ['Fabia','Octavia Tour','Octavia 2','Superb']; var thechild = document.getElementById(child); thechild.options.length = 0; var parent_value = parent.options[parent.selectedIndex].value; if (!parent_array[parent_value]) parent_value = ''; thechild.options.length = parent_array[parent_value].length; for(var i=0;i<parent_array[parent_value].length;i++){ thechild.options[i].text = parent_array[parent_value][i]; thechild.options[i].value = parent_array[parent_value][i];} } </script> Hello friends. I need a little help with this code i can't get to work. Under 500.000 euros a link to another website need to open when selected in the dropdown menu. Code: <input type="hidden" id="budget_min" name="budget_min" value="0" /> <input type="hidden" id="budget_max" name="budget_max" value="0" /> <select onchange="updatePriceLimit(this)"> <option value="http://othersite.com">-500.000 euros</option> <option value="500000-1000000">500.000 - 1.000.000 euros</option> <option value="1000000-2000000">1.000.000 - 2.000.000 euros</option> <option value="2000000-100000000">2.000.000+ euros</option> </select> <script type="text/javascript"> function updatePriceLimit(select) { if (select.value.search(/http/i)) { location.href=select.value; } else { var limit = select.value.split('-'); document.getElementById('budget_min').value = limit[0]; document.getElementById('budget_max').value = limit[1]; } } </script> TIA I created the following javascript to display info when you choose from a dropdown <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>View Local Contact </td> <td><select name="ContentListBox" id="ContentListBox" onchange="javascript:ShowDiv();"> <option value="">Select State</option> <option value="AK">Alaska</option> <option value="AL">Alabama</option> <option value="AR">Arkansas</option> </select></td> <td> </td> </tr> </table> <div id="AK" style="display:none;"></div> <div id="AL" style="display:none;"><div class="salesman">Marilyn O. Rogers </div> <div class="salesphone">Phone/Fax: 615-824-7804</div> <div class="salesemail">E-mail: <a href="mailto:morogers1@comcast.net">morogers1@comcast.net</a></div></div> <div id="AR" style="display:none;"><div class="salesman">Lonnie Muse</div> <div class="salesphone">Phone: 432-366-9213</div> <div class="salesemail">E-mail: <a href="mailto:muselon@sbcglobal.net">muselon@sbcglobal.net</a></div></div> When you choose the second one and then the third one the second choice does not disappear and it displays both. How can i refresh in between each one so that is displays only one? I need a short and simple script a (drop down menu) that I can duplicate about 100-150 times on a page. I need it to be universally compatible IE7-9, Firefox, Chrome, Opera. The one I was originally using worked incredibly slow in IE. Any help would be hugely appreciated and we can figure out a price on the script. Thanks a ton in advance. Hi guys. I was wondering if you maybe could help me with the following issue. I would like to make a menu that when you click it, a submenu slides beneath it, when you click it again it slides back up (so not automatically if you click another menu). I attached an image to clearify myself. This is what I came up with so far, but now I am stuck.. can somebody help me? http://www.webmention.com/menu.htm is the look I actually want.. seperated menu's and the submenu not 'in' the main menu.. Thanks! Hi all! I'm new and, well, I don't know a whole lot about javascript, honestly. I'm much more of an artistic design person than I am a coder. That said, I recently made a dropdown menu using an old version of Fireworks, but I've been having trouble getting it working on my site. The menu displays alright, but the dropdown does not appear right below it...instead, it's off and to the right somewhere. For the life of me, and with my limited knowledge, I cannot figure out how to fix it. The menu in question is the 'store' button on the following webpage- http://rlfcomic.com/test2.php# Note how the dropdown just seems to float at an arbitrary spot. Any ideas on what I'm doing wrong? i want to activate a dropdown menu with a lot of submenus and i have function setActive() { aObj = document.getElementById('nav').getElementsByTagName('a'); for(i=0;i<aObj.length;i++) { if(document.location.href.indexOf(aObj[i].href)>=0) { aObj[i].className='active'; } } } window.onload = setActive; but it activate me only the sub butons and i want the primary - the top buton active i have a css class separated can you help me ? what should i add in the code? I hope someone can help me. I am having a problem with a dropdown selection box. I think Javascript is the way to solve it, but I am unfamiliar with the language, any help would be much appreciated. My drop down box selection box is created dynamically with data from a mysql database. It is a list of artists/musicians. I have 1 column in the db table called artist_name and another called artist_id. The sql query selects both of these columns and displays artist names in the select box. What I need is for the artist_id to be sent along with whichever artist is selected in the select box to the next page upon submitting the form. I put in a input field, which I will make hidden eventually. But I want the input field to change to whatever the correct id is when the select box is changed. I am thinking that the way to do this would be with a javascript onchange event. Will this work ? If so I need help with the code. I have searched for examples online and while somewhat helpful, I am such a newbie with Javascript that I could not figure out how to modify the examples to what I need. Here is the php/mysql code I have so far: PHP Code: $query4 = "SELECT artist_id,artist_name FROM artists ORDER BY artist_name"; $result4 = mysql_query($query4) or die(mysql_error()); echo "<select name='artist'> <option value=''>Select Artist</option>"; while($row=mysql_fetch_array($result4)) { $artist_id=$row['artist_id']; echo "<option value='". $row['artist_name'] ."'>". $row['artist_name'] ."</option>"; } echo "</select> <input type='text' name='artist_id' id='artist_id' size='5' class='textfield' value='$artist_id'>"; HI I am trying to add a 'orderby' or 'sortby' dropdown to a website to give various options of order picked from a MySQL recordset, the example below is what I am looking for that changes on re-fresh and remembers the selection chosen. Example Site - Waterstones Bookstore I think it would be a mixture of Javascript and PHP?? I have searched for hours looking for a solution Many thanks in advance |