JavaScript - One Select List Updates All Select Lists
Hey Guys
When a user changes the select list called "reason_code_master" I need the uodatecodes() function to update all the other select list with the id of "reason_codes" with the same . How can I do this. <select size='1' onchange="updatecodes()" name='reason_code_master'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> Similar TutorialsI've been tasked to create a form where the user types a numeric item id into a text field. Typing this numeric item id into the field will update a select list when the item id matches a select list value. Can anyone help me with this as I don't know where to start?
I need help please. I'm trying to validate when a user selects an item from the equipment select list they must select a reason code as to why they are ordering the item. This must work across all rows. Also the field to the left of the equipment select list should allow the user to key in the item # of the part and the select list automatically gets selected with the part. How the heck do I do this. I tried the functions I have included but they suck! Please help me Tracy Code: <script> function validateReason(){ var tr, i=1; while(tr=document.getElementById('Child'+(i++))){ var txtV=tr.getElementsByTagName('input')[0].value var selS=tr.getElementsByTagName('select')[0].selectedIndex; if(txtV.length>0&&selS==0){alert('If you enter a quantity you must select a reason!');return false} } } function change_uids(uid){ var uids = document.getElementById("uids"); for (var i=0; i<uids.options.length; i++){ if (uids.options[i].value == uid.value){ uids.options[i].selected = true; break; } } } </script> <form method="POST" onsubmit="return validateReason(this) ;" action="" name="theForm" > <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='wic[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='num[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='wic[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> </table> <input type="submit" value="SUBMIT" name="submit"> </form> I have a cgi script (using perl for database queries) in which I have two select boxes. I am populating the left select box with rows from a database, and then provide buttons for people to move items to the right select box. So far so good, everything works, the move right, move left, and move right all and move left all buttons work, data is always sorted in both lists. My only problem is, when I click the submit button, the follow up program only displays data that was highlighted/selected in the right select box, not all of the data in the right select box. I don't know how to tell the script, via javascript, to highlight everything in the right select box when the submit form button is clicked. I would think i could just call a function via -onClick for the submit button. I could use some help with the function to select all data in that list. I can post code if it is helpful. Thanks, Taylor How do I reset selct lists like below. <form> <select size='4' STYLE='width: 164px' MULTIPLE id="num" name='num[]'> <option value='1' selected>1</option> <option value='2' selected>2 </option> <option value='3' selected>3</option> </select> <input type="button" name="reset" > </form> How can i get the below function to only select a value from the select list when there is an exact match. Let's say I type 54 in the text box it immediately selects 54921 value from the list? Code: <html> <head> <title>test</title> <script type="text/javascript"> function change_uids(uid){ var uids = document.getElementById("uids"); for (var i=0; i<uids.options.length; i++){ if (uids.options[i].value.substr(0,uid.value.length) == uid.value){ uids.options[i].selected = true; break; } } } </script> </head> <body> <form action="test.html" method="get"> <label for="uid">Your ID:</label><input type="text" id="uid" name="uid" onkeyup="change_uids(this)"/> <select id="uids" size="7" > <option value=""></option> <option value="12844">12844</option> <option value="54921">54921</option> <option value="54922">54922</option> <option value="25643">25643</option> <option value="61423">61423</option> <option value="43903">43903</option> <option value="58345">58345</option> <option value="61934">61934</option> </select> </form> </body> </html> I want to validate a select list that looks like the below select list. How can I do this when it is named "status[]". <select size='4' MULTIPLE name='status[]'> <option value='COMPLETE'>COMPLETE</option> <option value='ENTERED'>ENTERED</option> <option value='INSTALLED'>INSTALLED</option> </select> Hello everyone, after a few days of looking i give up i just don't know what to look for or how to do it. on this website "http://www.hunlock.com/blogs/Everything_You_Ever_Needed_To_Know_About_Video_Embedding there is a section called How to make a video select list. I have been able to replicate and modify it to my liking how ever i have one issue. i can't make my videos fullscreen. The videos have and give the option for full screen but the fullscreen doesn't work. i prefer this kind of code because it allows my webpage to select a video without changing the webpage and play it, i find it much more smoother then then multiple embedded videos in tabs (i don't even know what to call it so thats what i call it) just incase the website doesnt work or something i will post the script first part<div id='videoPlayback' style='width: 435px; height:350px; background-color: #800000;'></div> then <div id='selectDemo1' style='display: none'> <object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/-is63goeBgc"></param> <param name="wmode" value="transparent"></param> <embed src="http://www.youtube.com/v/-is63goeBgc&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"> </embed> </object> </div> <div id='selectDemo2' style='display: none'> <object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/c6SHsF1n9Qw"></param> <param name="wmode" value="transparent"></param> <embed src="http://www.youtube.com/v/c6SHsF1n9Qw&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"> </embed> </object> </div> then <A HREF="#" onclick='return playVideo("selectDemo1","videoPlayback")'>RvD2: Ryan vs. Dorkman 2</A><BR> <A HREF="#" onclick='return playVideo("selectDemo2","videoPlayback")'>Beatboxing Flute </A><BR> and finally<script type="text/javascript"> function playVideo(sourceId, targetId) { if (typeof(sourceId)=='string') {sourceId=document.getElementById(sourceId);} if (typeof(targetId)=='string') {targetId=document.getElementById(targetId);} targetId.innerHTML=sourceId.innerHTML; return false; } </script> i'm not sure the exact functions or how to write this kinda stuff from scratch so if you have any helpfull additions or suggestions please let me know. hi please help, i want to select numbers from a list box and add it to a text box with comma separated. my java script code does not work into browser but work fine into eclipse jsp view. Code: function passingNumbersToTextArea(numToCall,allNum) { var numFromList=document.getElementById(allNum); var numToTextArea=document.getElementById(numToCall); if(numToTextArea.value.search(numFromList.value)!=-1)//if duplicate Number is exist { alert("Duplicate Number Can not be added :"); return false; } else { if(numToTextArea.value.length!=0) { // If textarea has value than it added another value with comma seperated numToTextArea.value=numToTextArea.value+','+numFromList.value; return false; } else { numToTextArea.value=numFromList.value; return false; } } } jsp code <h:inputTextarea cols="10" rows="4" id="numberToCall" required="true" value="#{conferenceCall.numberToCall}" styleClass="form_input_box" /> <h:selectOneListbox styleClass="form_selectmenu" id="allNumbers" size="5" onclick="passingNumbersToTextArea('numberToCall','allNumbers');"> <f:selectItem itemValue="9971701077" itemLabel="Sharad : 9971701077"/> <f:selectItem itemValue="9990102381" itemLabel="Saurabh : 9990102381"/> </h:selectOneListbox> javascript debugger shows error Error ``numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Exception ``TypeError: numToTextArea is null'' thrown from function passingNumbersToTextArea(allNum=string:"allNumbers", numToCall=string:"numberToCall") in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 21. [e] message = [string] "numToTextArea is null" Exception ``TypeError: numToTextArea is null'' thrown from function onclick(event=MouseEvent:{0}) in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 1. [e] message = [string] "numToTextArea is null" Error ``TypeError: numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Thanks & Regards: Saurabh I have html like this Code: <form> <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> some code...... <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> some code....... <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> I need to change all select lists options to "Shipped" if admin clicks on "Shipped" on top of the page and "Processing" if customer clicks on "Processing" link (<a href="javascript:select_processing()">Processing</a>) Can somebody help me in doing so? So I have the below form. How can I validate that if the user enters a quantity in the field they also must select a reason code. How can I do this.\ Code: <form name="theForm" onsubmit="validate()"> <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4395' name='itemid[]' > </tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4396' name='itemid[]' > </tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4353' name='itemid[]' > </tr> <tr id='Child4'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4355' name='itemid[]' > </tr> </table> </form> Hi there, Is there any way in JS to convert all items in a Select to a numbered list? I can imagine something like Code: for (Scount=0;Scount<select.length;Scount++) and then process each value in the Select to a numbered list, but I can't figure out how and there seems to be no one on the internet with the same goal... Am quite a newbie! Thanks in advance for your help! Thomas the code below was got from <http://www.javascriptkit.com/javatutors/selectcontent2.shtml> I was following to tutorial to learn how to create multi-level select list in javascript. i have gone through it but wanted to print the individual selected item in each option, i could not. the first worked well for be because the selected options are manually typed, but the last option became difficult because they are dynamically loaded. Please can anyone guild me on how to print the selected option of the second field? <form name="classic"> <select name="countries" size="4" onChange="updatecities(this.selectedIndex)" style="width: 150px"> <option selected>Select A City</option> <option value="usa">USA</option> <option value="canada">Canada</option> <option value="uk">United Kingdom</option> </select> <select name="cities" size="4" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)"> </select> </form> <script type="text/javascript"> var countrieslist=document.classic.countries var citieslist=document.classic.cities var cities=new Array() cities[0]="" cities[1]=["New York|newyorkvalue", "Los Angeles|loangelesvalue", "Chicago|chicagovalue", "Houston|houstonvalue", "Austin|austinvalue"] cities[2]=["Vancouver|vancouvervalue", "Tonronto|torontovalue", "Montreal|montrealvalue", "Calgary|calgaryvalue"] cities[3]=["London|londonvalue", "Glasgow|glasgowsvalue", "Manchester|manchestervalue", "Edinburgh|edinburghvalue", "Birmingham|birminghamvalue"] function updatecities(selectedcitygroup){ citieslist.options.length=0 if (selectedcitygroup>0){ for (i=0; i<cities[selectedcitygroup].length; i++) citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1]) } } </script> I currently have two html select list boxes side by side on a form, two buttons in between the boxes to move items from list box to the other, and a javascript function to control the movement of the items from one box to the other. Here is the javascript: Code: function MoveSelected(from, to) { var lstFrom = $(from); var lstTo = $(to); for (var i = 0; i<lstFrom.length;i++) { if ( lstFrom[i].selected ) { var elOptNew = document.createElement('option'); elOptNew.text = lstFrom[i].text; elOptNew.value = lstFrom[i].value; try { lstTo.add(elOptNew, null); // standards compliant; doesn't work in IE } catch(ex) { lstTo.add(elOptNew); // IE only } } } for (var i = lstFrom.length-1; i>=0;i--) { if ( lstFrom[i].selected ) { lstFrom.options[i] = null; } } } Here are the two html form select list boxes (lstAvailProd is the starting list box that lists the initial data and lstSelectProd is the destination list box): Code: <td width="10%" valign="center"> <a href="javascript: MoveSelected('lstAvailProd','lstSelectProd');"><IMG SRC="buttons/right_arrow.gif" style="padding-bottom: 2px;" /></a><br /><br /> <a href="javascript: MoveSelected('lstSelectProd','lstAvailProd');"><IMG SRC="buttons/left_arrow.gif" /></a> </td> I was wondering if anyone could tell me how I could modify my code to allow for the selection of all the data in the starting list box by only selecting and moving the first item in the list to the destination list box? The first item is called "All Products", so instead of actually selecting every product in the starting list and moving them to the destination list, I would like the code to see that if the "All Products" list item is moved to the destination list, move all the other list items in the destination list back to the starting list. Here's an example of what the code for each list box looks like: Starting List Box: Code: <select name="lstAvailProd" id="lstAvailProd" multiple="true" size="8" style="width: 250px;"> <option value="-1">{All Products}</option> <option value="1">Product 1</option> <option value="2">Product 2</option> <option value="3">Product 3</option> <option value="4">Product 4</option> <option value="5">Product 5</option> </select> Destination List Box: Code: <select name="lstSelectProd" id="lstSelectProd" multiple="true" size="8" style="width: 250px;"> </select> Any help would be appreciated, thanks!! Hello All, I currently am trying to make a long list of checkboxes function like a multi-select box would. I would like to be able to shift-select two checkboxes and have for example, the X number of boxes in between all be selected. Is there an efficient way to go about doing this? Thanks in advance. I have selectitem list which has name value pairs SelectItem(value, name), i need to iterate in JS and i need to populate in to option list, like below, but it dint work for me. Please any help function loadme(listVle){ // listVle is the List<SelectItem> var ele = document.getElementById('numadts'); for (var i=0;i<listVle.length;i++) { var elOpt = document.createElement('option'); var fldName = listVle.item(i).getAttribute('name'); // This line the problem is elOpt.text = fldName; elOpt.value = fldName; try { ele.add(elOpt, null); } catch(ex) { ele.add(elOpt); } } } and the HTML <BODY> <FORM> <select name="numadts" id="numadts" onclick="loadme()""> </select> </FORM> </BODY> Hi there. With the below script I'm trying to validate if the user enters a quantity in the text box they must select a reason for ordering and if the user selects a reason code but forgets to enter a quantity it should alert to enter a quantity. Right now it validates the reason code but not the quantity. Please help. Code: <script> function validateReason(){ var tr, i=1; while(tr=document.getElementById('Child'+(i++))){ var txtV=tr.getElementsByTagName('input')[0].value var selS=tr.getElementsByTagName('select')[0].selectedIndex; if(txtV.length>0&&selS==0){alert('If you enter a quantity you must select a reason!');return false} } return true; } </script> <form method="POST" onsubmit="return validateReason(this) ; " action="Order_Process.php" name="theForm" > <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='INSUFFICIENT' >INSUFFICIENT</option> <option value='MISPLACED' >MISPLACED</option> <option value='NOT ORDERED' >NOT ORDERED</option> <option value='PLANOGRAM CHANGE' >PLANOGRAM CHANGE</option> <option value='SHORT' >SHORT</option> </select></td> </tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='MISPLACED' >MISPLACED</option> <option value='SHORT' >SHORT</option> </select></td> </tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='MISPLACED' >MISPLACED</option> <option value='SHORT' >SHORT</option> </select></td> </tr> </table> <input type="submit" value="submit" name="submit"> </form> If i have a drop down list on my website, and i want to use javascript to change its selected value, however, i do not have the id/name attribute of the option i want to select, only have the "value" attribute of the option, can it be done? <select name="category"> <option value="">No Preference</option> <option value="Apples">Apples</option> <option value="Oranges">Oranges</option> <option value="Pears">Pears</option> <option value="Banana">Banana</option> </select> I imagine somehow.. selecting the options and looping through them and match the value. Really new to javascript, can anyone advise? Thanks in advance! so, I can pass a value from a select list to another function which then decides which function to call, but I want to cut out the middleman, and make the values the function calls, and call them directly on the onchange... I imagine something like this: Code: <select id="select" onchange="this.value"> <option selected value="function1()">Funtion 1</option> <option value="function2()">Function 2</option> <option value="function3()">Function 3</option> </select> is it possible? is it possible to refresh a select list on it's own without refreshing the whole page?
Hey chaps, hope someone can help with this: I have a PHP form, with a couple of dynamic Select menus, which are populated from two SQL tables: // tbl_main_colour: Code: ID, NAME 1, Red 2, Blue 3, Green // tbl_shade_colour: Code: ID, NAME, FK_MAIN_COLOUR_ID 1, Light Red, 1 2, Dark Red, 1 3, Light Blue, 2 4, Dark Blue, 2 5, Light Green, 3 6, Dark Green, 3 What I'm after is something to filter the second select option, after the first select option has been chosen // Select 1: Code: Red // Select 2: Code: Light Red Dark Red I'm pretty sure this is possible, but not sure how to go about it, any help would be most appreciated. |