JavaScript - Need Help With Spry Validation Select Menu
Hi All,
I searched for an answer but didn't find anything that matched my issue. I am using Dreamweaver CS5 and have a few spry validation select boxes on my page. All but one are working correctly. The one in question is spryselect1 ("spryEquipLoc"). For some reason (which I cannot figure out) this field will display the selectRequiredState even after a selection has been made. Thanks in advance for any help. Here is the code: 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> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script> <script src="javascripts/Calendar.js" type="text/javascript"></script> <!--<script src="javascripts/datetimepicker_css.js"></script>--> <script type="text/javascript"> var categories = []; categories["startList"] = ["Equipment issue","Log issue","Operator error","Media issue","Satellite issue","Program issue","Playlist issue","Promo issue"] categories["Equipment issue"] = ["Digibeta deck","XDCAM deck","Video monitor","Chyron","Switcher","Media port","Downstream keyer","Asset base PC","Device server","Rapid Play X PC","Satellite receiver","Video server","Miranda wall","Crispen automation","Vertigo X-Play"]; categories["Log issue"] = ["Log/Playlist mismatch","Log timing light","Log timing heavy","Incorrect duration","Wrong start time","Events deleted"]; categories["Operator error"] = ["Operator Name1","Operator Name2","Operator name3"]; categories["Media issue"] = ["Damaged tape","Missing media","Dublist not received","Bad media file","Snipe Issue","Bug Issue","Missing audio","Audio out of sync","Audio clipping/distorted","Audio level too low","Embedded credits"]; categories["Satellite issue"] = ["Black on air", "Signal outage", "Sun outage", "Closed captions","Audio issue","Transmitter related"]; categories["Program issue"] = ["Program light","Program heavy","Incorrect program","Incorrect material ID","Program replaced","Incorrect segment lengths","Embedded credits"]; categories["Playlist issue"] = ["Playlist light","Playlist heavy", "Incorrect playlist loaded", "Wrong playback source"]; categories["Promo issue"] = ["Incorrect material ID","Incorrect duration","Incorrect snipe","Incorrect snipe duration","Promo replaced"]; var nLists = 2; // 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['frmOnAirActivity']['List'+i].length = 1; document.forms['frmOnAirActivity']['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 init() { fillSelect('startList',document.forms['frmOnAirActivity']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>On Air Activity Form</title> <style type="text/css"> body,td,th { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 14px; color: #052F47; } body { background-color: #8E8E8E; background-image: url(); background-repeat: no-repeat; } #form { behavior: url(PIE.htc); font-family: Verdana, Geneva, sans-serif; background-repeat: repeat; font-size: 14px; padding: 10px; width: 660px; border-radius: 0px 0px 20px 20px; box-shadow: #666 10px 10px 10px; border-top-style: none; border-right-style: outset; border-bottom-style: outset; border-left-style: none; background-color: #589DC6; float: right; } #wrapper { margin: auto; width: 860px; } </style> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" /> <link href="css/Calendar.css" rel="stylesheet" type="text/css" /> </head> <body> <script type="text/javascript"> // show and hide sections of a form function preparePage() { document.getElementById("List1").onclick = function() { if (document.getElementById("List1").value=="Equipment issue") { // use CSS style to show it document.getElementById("Equipment").style.display = "block"; document.getElementById("Satellites").style.display = "none"; } else if (document.getElementById("List1").value=="Satellite issue") { // use CSS style to show it document.getElementById("Satellites").style.display = "block"; document.getElementById("Equipment").style.display = "none"; } else { // hide the div document.getElementById("Equipment").style.display = "none"; document.getElementById("Satellites").style.display = "none"; } }; // now hide it on the initial page load. document.getElementById("Equipment").style.display = "none"; document.getElementById("Satellites").style.display = "none"; } window.onload = function() { preparePage(); }; </script> <div id="wrapper"> <img src="Graphics/banner.png" alt="Banner" width="860" height="84" /> <div id="form"> <form id="frmOnAirActivity" name="frmOnAirActivity" method="post" action=""> <span id="spryAirdate"> <label for="Airdate">Airdate</label><br/> <input type="Text" id="Airdate" tabindex="1" /> <img src="graphics/cal.gif" onclick="javascript:showCalendar('Airdate')" style="cursor:pointer" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></p> <p> <span id="spryDiscrepType"> <label for="List1">Event Category</label><br /> <select name="List1" id="List1" tabindex="2" onchange="fillSelect(this.value,this.form['List2'])"> <option selected></option> </select> <span class="selectRequiredMsg">Please select an item.</span></span> </p> <span id="spryDiscrepSubType"> <label for="List2">Detail</label><br /> <select name="List2" id="List2" tabindex="3" onchange="fillSelect(this.value,this.form['List3'])"> <option selected></option> </select> <span class="selectRequiredMsg">Please select an item.</span></span> <p> <div id="Equipment"> <span id="spryEquipLoc"> <label for="EquipLoc">Equipment Location</label><br/> <select name="EquipLoc" id="EquipLoc" tabindex="4"> <option selected></option> <option>Master Control</option> <option>Media Services</option> <option>Central Tape</option> </select> <span class="selectRequiredMsg">Please select an item.</span></span> <p> <span id="spryEquipID"> <label for="EquipID">Equipment ID</label><br /> <input type="text" name="EquipID" id="EquipID" tabindex="5" /> <span class="textfieldRequiredMsg">A value is required.</span></span> </div> <p> <div id="Satellites"> <fieldset><legend>Affected Satellites:</legend> <table width="424"> <tr> <td width="152"><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_12" /> NET Sat1</label></td> <td width="119"><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_16" /> Net Sat2</label></td> <td width="137"><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_20" /> Net Sat3</label></td> </tr> <tr> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_13" /> Net Sat4</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_17" /> Net Sat5</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_21" /> Net Sat6</label></td> </tr> <tr> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_14" /> Net Sat7</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_18" /> Net Sat8</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_22" /> Net Sat9</label></td> </tr> <tr> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_15" /> Net Sat10</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_19" /> Net Sat11</label></td> <td><label> <input type="checkbox" name="Satellites_" value="checkbox" id="Satellites_23" /> Net Sat12</label></td> </tr> </table> </fieldset> </div> <fieldset> <legend>Network:</legend> <table width="424"> <tr> <td width="152"> <label> <input type="checkbox" name="Network_1" value="checkbox" id="Network_1" /> Networl_1</label> </td> <td width="119"> <label> <input type="checkbox" name="Network_2" value="checkbox" id="Network_2" /> Network_2</label> </td> <td width="137"> <label> <input type="checkbox" name="Network_3" value="checkbox" id="Network_3" /> Network_3</label> </td> </tr> </table> </fieldset> <p> <label for="OnAirVariance">On Air Variance</label> <input name="OnAirVariance" type="checkbox" value="" /> <p> <span id="spryDescription"> <label for="Description">Description</label><br /> <textarea name="Description" id="Description" cols="45" rows="5" tabindex="6"></textarea> <span class="textareaRequiredMsg">A value is required.</span></span> <p> <span id="spryResolution"> <label for="Resolution">Action Taken</label><br /> <textarea name="Resolution" id="Resolution" cols="45" rows="5" tabindex="7"></textarea> <span class="textareaRequiredMsg">A value is required.</span></span></p> </form> </div> </div> <script type="text/javascript"> var sprytextfield1 = new Spry.Widget.ValidationTextField("spryAirdate", "date", {validateOn:["blur"], useCharacterMasking:true, format:"mm/dd/yyyy"}); var sprytextfield2 = new Spry.Widget.ValidationTextField("spryEquipID", "none", {validateOn:["blur"]}); var spryselect1 = new Spry.Widget.ValidationSelect("spryEquipLoc", {validateOn:["blur"]}); var spryselect2 = new Spry.Widget.ValidationSelect("spryDiscrepType", {validateOn:["blur"]}); var spryselect3 = new Spry.Widget.ValidationSelect("spryDiscrepSubType", {validateOn:["blur"]}); var sprytextarea1 = new Spry.Widget.ValidationTextarea("spryDescription", {validateOn:["blur"]}); var sprytextarea2 = new Spry.Widget.ValidationTextarea("spryResolution", {validateOn:["blur"]}); </script> </body> </html> Similar TutorialsHi, I am having problem in validating my form using spry tools. The problem is that if I try to include any other validation other than spry along with spry validation the spry validation does not work. Plzz tell a possible solution Need Help with Spry Menu Bar This is the site I am working on: http://www.alpinelakesair.com/newsite/index.php To quickly summarize: (without getting into the *why* of things) - the website has only two pages: 1=index.php, 2=charter-flights.php - the homepage links to specific tabs within the spry region of the main menu bar, which is located on page the 2nd page. - all the sub pages of the site are located within the spry content of the spry tabs of the menu bar (this is so the header image never has to reload) So, the idea goes that you click on the tabs of the home page and it brings you to the 2nd page with the corresponding menu bar item already highlighted. The pages work in Safari and Firefox on my Mac - but - when you try click on the first four tabs from the homepage in Internet Explorer it doesn't open any content. If you click on the last three tabs it opens content - but all the content, and the sub-spry regions do not work... I am new to spry, so if you help please make your answers for someone with a little but not much spry knowledge. Please let me know if more information is needed.. I am reposting this as the issue has not been resolved... alex I am finishing up my Form page, and totally forgot to have a numeric only field. So I added it and I can't get it to work. I also am having issues throwing an error when you don't select at least one topping. And are these lines correct? Code: document.cookie = "toppings=" + encodeURIComponent(document.getElementsByName("toppings[]").value); Code: document.cookie = "extra=" + encodeURIComponent(extra); Here is a link to the page hosted on my dropbox http://dl.dropbox.com/u/49211616/dw/...orderPage.html Javascript: Code: function validateOrder () { var crustSelection = document.orderForm.crust.value; var crustPrice; //Adds $1 for Deep DishParmesagn, and Sourdough var count = 0; //Amount of Toppings Selected var choice = ""; //Toppings Selected list var x = ""; //Don't need for the Cookie var extra = 0; //extra charge for toppings over 3 try{ var error = ""; // Initialize Var to store the error messages. if(document.getElementById("delivery").checked != true && document.getElementById("takeout").checked != true) { error=error+"Order Type is required.\n" } if(document.getElementById("fname").value == "") { error = error + "First Name is required.\n"; } if(document.getElementById("lname").value == "") { error = error + "Last Name is required.\n"; } if(document.getElementById("address").value == "") { error = error + "Street address is required.\n"; } if (isNaN(document.getElementById("quantity"))) { error = error + "Enter Pizza Quantity in Numbers Only.\n"; } if(document.getElementById("crust").value == "") { error = error + "Crust Type is required.\n"; } if(document.getElementsByName("toppings").value == 0) { error = error + "Select at Least One Topping.\n"; } if(error == "") { // save all the information in the cookie document.cookie = "firstName=" + encodeURIComponent(document.getElementById("fname").value); document.cookie = "lastName=" + encodeURIComponent(document.getElementById("lname").value); document.cookie = "address=" + encodeURIComponent(document.getElementById("address").value); document.cookie = "order=" + encodeURIComponent((document.getElementById("delivery").checked) ? "delivery" : "takeout"); document.cookie = "quantity=" + encodeURIComponent(document.getElementById("quantity").value); document.cookie = "quantity=" + encodeURIComponent(document.getElementById("quantity").value); document.cookie = "crust=" + encodeURIComponent(document.getElementById("crust").value); document.cookie = "toppings=" + encodeURIComponent(document.getElementsByName("toppings[]").value); alert("Order successfully Placed!"); } else { alert(error); } } catch(ex) { alert("An error occurred!.\n" + "Error Name : " + ex.name + "\nError Message : " + ex.message); } for (var i=1; i<11; i++) { x = document.orderForm['toppings' + i].value; if (document.orderForm['toppings' + i].checked) { choice = choice + " " + x ; count ++; } } if (choice.length <= 0) { choice = choice + "NONE"; } if (count > 3) { extra = (count - 3) * 1 } document.cookie = "extra=" + encodeURIComponent(extra); } </script> HTML: Code: <form name = "orderForm" onsubmit="validateOrder()"> <table width="600" border="0"> <tr> <th scope="col" width="400" align="left"><b>First Name</b><br /><input type="text" id="fname" name="fname" size=30> <br /> <br /> <b>Last Name</b><br /> <input type="text" id="lname" name="lname" size=30> <br /> <br /> <b>Street Address</b><br /> <input type="text" id="address" name="address" size=30> <br /> <br /> <input name="orderType" value="delivery" id="delivery" type="radio">Delivery</font> <input name="orderType" value="takeOut" id="takeout" type="radio">Take Out</font></th> <th scope="col" width="200" align="Left"> How Many Pizzas? <input type="text" id="quantity" name="quantity" size=5> <br /> <br /> <select name="crust" id="crust"> <option selected value="false">Select Crust Type</option> <option value="regular">Regular Crust</option> <option value="thin">Thin Crust</option> <option value="deep">Deep Dish</option> <option value="Parmesagn">Parmesagn Cheese</option> <option value="sourdough">Sourdough</option> </select> <br /> <br /> Select at Least One Topping: <br /> <br /> <input name = "toppings1" type = "checkbox" value = "extraCheese"> Extra Cheese<br> <input name = "toppings2" type = "checkbox" value = "sausage"> Sausage<br> <input name = "toppings3" type = "checkbox" value = "pepperoni"> Pepperoni<br> <input name = "toppings4" type = "checkbox" value = "bacon"> Bacon<br> <input name = "toppings5" type = "checkbox" value = "canadianBacon"> Canadian Bacon<br> <input name = "toppings6" type = "checkbox" value = "mushroom"> Mushroom<br> <input name = "toppings7" type = "checkbox" value = "pineapple"> Pineapple<br> <input name = "toppings8" type = "checkbox" value = "onion"> Onion<br> <input name = "toppings9" type = "checkbox" value = "olive"> Olive<br> <input name = "toppings10" type = "checkbox" value = "greenPepper"> Green Pepper<br></th> </tr> </table> <input name="submit" type="submit" value="submit" /><input name="" type="reset" /> </form> Hi I have a form. In this form i have a pop down menu with 1,2,3,4,5 numbers in it. And after that i have 8 more form fields. what i want is when user select any number from pop down menu then these 8 fields should appear. for example when user select 2 from pop down menu then then these set of fields should appear twice i mean 8+8=16. and so on. my code is here 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=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <select name="jumpMenu" id="jumpMenu"> <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> </select> </p> <p> Type : <select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)"> <option value="Delux">Delux</option> <option value="king">king</option> <option value="exe">exe</option> </select> </p> <p> <label>Number: <input name="textfield" type="text" id="textfield" size="5" /> </label> </p> <p> <label>Name: <input type="text" name="textfield2" id="textfield2" /> </label> </p> <p>Date Arr: <label> <input type="text" name="textfield3" id="textfield3" /> </label> </p> <p>Dep Date: <label> <input type="text" name="textfield4" id="textfield4" /> </label> </p> <p> <label> <input type="checkbox" name="checkbox" id="checkbox" /> Extra</label> </p> <p> <label> <input type="checkbox" name="checkbox2" id="checkbox2" /> Park</label> </p> <p>Remarks: <label> <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> </label> </p> </form> </body> </html> how this can be done in js The following does not work properly in IE, FF, or Chrome: Javascript: Code: function validateZIP() { var zipRegEx = /^[0-9]{5}$/; // ZIP must be a 5-digit number if(document.searchForm.searchBy.selectedIndex == 2) // Only applies to 3rd item in pull-down menu { if(!document.searchForm.searchBy.value.match(zipRegEx)) // If value of input box does NOT meet zipRegEx condition { alert("ZIP must be a five-digit number!"); // Alert user with popup box document.searchForm.keyword.style.backgroundColor = "rgb(255,200,200)"; // Inform user which input box contains the error return false; // Kill the search from executing on the DB } else { document.searchForm.keyword.style.backgroundColor = "rgb(255,255,255)"; // If value of input box MEETS zipRegEx condition, continue executing } } return true; } HTML form: Code: <form name="searchForm" action="<?php echo $_SERVER['PHP_SEARCH']; ?>" method="POST"> Please enter a keyword, then select a parameter to search by: <br> <input type="text" name="keyword"> <select name="searchBy"> <option value="Name" />Name <option value="Required Package" />Required Package <option value="ZIP" />ZIP <option value="State" />State </select> <br> <input type="submit" name="submit" value="Search" onclick="return validateZIP();"> <input type="reset" value="Clear"> </form> Any ideas on why this JS function returns false when i enter "12345"? Hi I wanna to have two select boxes, one of them will contain a list of provinces, and on the other I wanna have a list of cities, but based on selected province. When province selects, cities select box must be changed, too. I don't wanna use AJAX for this purpose, as the server is already too busy and I don't like to disturb it more. So if anyone can provide a solution, just by Javascript and not with AJAX, I would be appreciate it. Cheers! I have two select menus, the second menu items should be determined based on the selected item of the first menu, and the problem I face is about using document.write() in adding the select menu items, when I write the items like this it work: Code: <select name="cities" > <script type="text/javascript"> document.write("<option value=''>city1</option>"); document.write("<option value=''>city2</option>"); document.write("<option value=''>city3</option>"); </script> </select> but when I put them in a function they wrote as a text not a menu item, and I must use a function and use if or switch in it, so what's the solution? Hi guys, I am after a script which will has parametres to modify the select menu in webpages. I have looked at niceforms http://www.emblematiq.com/lab/niceforms/demo/ However i dont know how to apply it. Any tips would be much appreciated. George Hello, I am trying to make a custom select menu. Here is what I have so far: http://mikewgd.com/wp-content/portfo...custom-select/ Im just stuck at getting the <li> to become selected and etc... I am using this as reference: http://v2.easy-designs.net/articles/replaceSelect/ -- Im not using there script exactly Im doing it a different way. Im doing it more as a dropdown menu Code: <ul class="select"> <li class="selected"> cheese <ul class="drop"> <li>milk</li> <li>bread</li> <li class="selected">cheese</li> <li>pickles</li> <li>salsa</li> </ul> </li> </ul> Hello all! I'm about to use this script below for a project I have. It works great but unfortunately I can't get it to read select menu (selected option) values. It returns undefined. I've asked the author but had no response as yet, so I was wondering if anyone else could see why it wouldn't read the select menu value. Code: var functionname = function () {} functionname.prototype = { options : {}, generateShortCode : function() { var content = this['options']['content']; delete this['options']['content']; var attrs = ''; jQuery.each(this['options'], function(name, value){ if (value != '') { attrs += ' ' + name + '="' + value + '"'; } }); return '[googleMap' + attrs + ']' + content + '[/googleMap]' }, sendToEditor : function(f) { var collection = jQuery(f).find("input[id^=myplugin]:not(input:checkbox),input[id^=myplugin]:checkbox:checked"); var $this = this; collection.each(function () { var name = this.name.substring(9, this.name.length-1); $this['options'][name] = this.value; }); send_to_editor(this.generateShortCode()); return false; } } var myfunction = new functionname(); Hello, I'm trying to populate an HTML drop down list with data from an XML file but have failed miserably so far using examples I've found. Please help. Thanks, Richard hi guys! i would like to know the script for me to auto select an option in a menu on a single click. so i have two pages. on the first page is the button. second page is the drop down menu. menu has selection "fruit" "vegies" "meat". by default fruit is selected. when i click on that button it will automatically select the menu on the second page for "meat". thanks!! *Edit: I thread title should probably be "Initialize indices..."* I've done quite a bit of research but couldn't find what I need to know so here I am. I have some javascript generated by php that reads a configuration file to add options to a select menu. This is somewhat irrelevant but... these options are removed from the menu when clicked and data related to the option is shown on the page... and the option gets re-added when the data is closed. I need the option to go back in the correct place/order in the select menu... which wouldn't be a problem if I could initialize the indices of the menu's options. They need to be initialized because when the page is created, saved settings are read and certain options are not shown in the list because they may already be shown according to the settings... meaning... since browsers automatically increment the indices of the options by 1 (starting at 0), if data is closed that was initially open and therefore not in the select menu at first... the key/index associated with that data will likely not match the correct menu order. Code: <script type="text/javascript"> function addOptionToSelect(selectID,index,offset,val,txt) { var elSel = document.getElementById(selectID); elSel.options[index+offset].value = val; elSel.options[index+offset].text = txt; } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } <?php foreach ($props as $k => $prop) { if (!in_array($prop, $_SESSION['crProps'])) { ?> addLoadEvent(addOptionToSelect('propertySelect',<?php echo $k; ?>,1,'?p=<?php echo $prop; ?>&k=<?php echo $k; ?>','<?php echo $prop; ?>')); <?php } } ?> </script> For example, suppose I have the following potential data sets: a,b,c,d,e,f In the config file that helps create the page, suppose it is something like: <Default>0:a|2:c|3:d</Default> (FYI: I've designed it so that the data set names/options are separated by the pipe character ("|") and their corresponding index is the number to the left of the colon.) Then the select menu that is initially generated would be something like: (Every other data set name except for what is already open by default.) <select id="bleh"> <option value="b">b <option value="e">e <option value="f">f </select> And by default, browsers would assign the indices like so: (skipping getElementById and all that...) select.options[0].value = b select.options[1].value = e select.options[2].value = f Whereas, I need it to be initialized like this: select.options[1].value = b select.options[4].value = e select.options[5].value = f So that when the data sets initially open are closed (a, c, or d)... they get put in the correct position in the list. I just thought of something... it's a little inefficient (OCD lol) but it should work and at worst would only cost a couple of milliseconds of processing time. A solution to this problem might be to load the menu with all options so that their indices are correct... and remove the defaults afterward. I'll try it. the script below should open a new window with a url specified in the select area. However, my script ignores the changes in the select area. it keeps opening the same page. I was wondering could someone take a look and tell me why? Thank you very much. <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> Jump Menu</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <script type="text/javascript"> function jump_menu() { var i=document.getElementById("page_select").selectedIndex; document.getElementById("jump_to_page").onclick=function() { (i==0) ? alert("Please select a page to go"):window.open("http://www."+document.getElementById("page_select").options[i].value); } } window.onload=jump_menu; </script> </head> <body> <select id="page_select"> <option>Select a Page</option> <option value="yahoo.ca">Yahoo</option> <option value="topnews.ru">Top News</option> <option value="google.com">Google</option> <option value="amazon.com">Amazon</option> </select> <button type="button" id="jump_to_page">Go</button> </body> </html> </code> I am trying to write script that allows a user to select a new page using a select menu. But if a user changes mind and clicks Back button. i want a use to see again "Select a New Page" as a first option in the select menu. instead i see the page that was chosen before. in firefox, even when i click Refresh button, the select menu does not go back to its initial format. I tried to use the principle that each time window is loaded, the selected Index would be 0. it is not working. Could anyone give me a hint on how to fix this problem? my script is below. <html> <head> <title>Jump Menu 2</title> <script type="text/javascript"> function new_page() { var selectmenu=document.getElementById("states_form").states_select; selectmenu.onchange=function new_state() { var i=selectmenu.selectedIndex; var state=selectmenu.options[i].value; var new_page="http://www.50states.com/"+state+".htm"; location.href=new_page; window.onload=function select_reload() { i=0; } } } window.onload=new_page; </script> </head> <body> <form id="states_form"> <select name="states_select"> <option value="0"> -- Select a New State--</option> <option value="nebraska"> Nebraska</option> <option value="texas"> Texas</option> <option value="florida">Florida </option> <option value="oregon"> Oregon</option> <option value="wisconsi"> Wisconsin</option> </select> </form> </body> </html> I am hoping you guys can help me with this issue. What I am trying to do is fairly simple, depending on what option you select in the menu I want the picture to change to different picture. The code that I posted below works perfectly except for one problem. I need the option value to display the color name, and not have the image code in it. I have researched ways to do this without having to use "value" but I just can't find one that works. Can someone please help me? Thanks in advance for any help given! Code: function changeimg(){ document.getElementById('colors').src=document.getElementById('color_dropdown_options').value } Code: <label> <select name="color" class="dropdown_options" id="color_dropdown_options" onchange="changeimg()"> <option value="/images/thumbnails/image1.jpg">White</option> <option value="/images/thumbnails/image2.jpg">Blue</option> <option value="/images/thumbnails/image3.jpg">Green</option> </select> </label> Code: <div id="display"><img src="/images/thumbnails/image1.jpg" width="270" height="382" alt="" id="colors" /> Trying to get the divs to switch style properties when selected form select menu. Any help would be great! Code: <script type="text/javascript"> function showstuff(element){ if(document.getElementById(element).style.display = 'block') { document.getElementById(have).style.visibility="block"; document.getElementById(look).style.visibility="none"; } else if(document.getElementById(element).style.visibility = 'block') { document.getElementById(look).style.visibility="block"; document.getElementById(have).style.visibility="none"; } } </script> <select name="type" onchange="showstuff(this.value);"> <option value="look">Look</option> <option value="have">Have</option> </select> <div id="have" style="display:block;">Have</div> <div id="look" style="display:none;">Look</div> I'm tearing my hair out with this one and can't figure out why it won't work, and am hoping someone could help a Javascript noobie out. Basically, I need the script to hide two divs if one of the options in a <select> menu is selected. Here's the code I've got for the Javascript: Code: function typeoflisting() { var selectform = document.getElementById('propertytype'); if (selectform.options[selectedIndex].value == "sell") { document.getElementById('per_week').style.display = 'none'; document.getElementById('bond').style.display = 'none'; } else { document.getElementById('per_week').style.display = 'block'; document.getElementById('bond').style.display = 'block'; } } Here's the <select> form: Code: <select id="propertytype" name="propertytype" class="select" onchange="typeoflisting()"> <option value="lease">I'd like to lease a property to tenants</option> <option value="sell">I'd like to sell a property</option> <option value="share">I'd like to share a property</option> </select> And here's the first div I'm attempting to hide: Code: <div id="per_week" style="float: left;"> per week</div> And the second div I'm attempting to hide: Code: <div style="float: left; padding: 20px 20px 0px 0px;" id="bond"> <h3>Bond</h3> <input type="text" class="text" value="$"/> </div> Could anyone please tell me what I'm doing wrong? |