JavaScript - Populate 2nd Dropdown(disabled) On Selecting Value In First Dropdown
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. Similar Tutorialsi m required to script the coding in which if we select an option from dropdown menu a text should be apprehend in disabled text field.. i dont have any idea about javascripting so sorry for being so dump... i need resultant in this form Hi, How can I auto populate the data by dropdown selected? and my dropdown result already appear as well, the code as following: PHP Code: <?php echo '<tr> <td>'.$customer_data.'</td> <td><select name="customer_id">'; foreach ($customers as $customer) { if ($customer['customer_id'] == $customer_id) { echo '<option value="'.$customer['customer_id'].'" selected="selected">'.$customer['name'].'</option>'; } else { echo '<option value="'.$customer['customer_id'].'">'.$customer['name'].'</option>'; } } echo '</select> </td> </tr>'; ?> and the result of dropdown above listed as admin customer1 FREE loaded from following db PHP Code: INSERT INTO `my_customer` (`customer_id`, `name`, `firstname`, `lastname`) VALUES (8, 'admin', '', ''), (6, 'customer1', 'ok', ''), (7, 'FREE', 'marj', 'om'); so whenever dropdown selected i want the all data below: PHP Code: <tr> <td><?php echo $firstname; ?></td> <td><?php echo $lastname; ?></td> </tr> also auto populate, it seem need javascript/ajax/jquery to fixed it, I was Wondering if someone could help me, and thanks in advance I have up to 3 dropdown lists that I can select using javascript functions. Depending on what I select in the first dropdown loads what is in the 2nd drop down and so on. i want to be able to select the first drop down and it skips the 2nd one and displays the 3rd one. How do I do that with the current functions I am using. Code: function cboSourceChange(){ var iSource = document.frmHarvestForm.cboSource.options[document.frmHarvestForm.cboSource.selectedIndex].value; var iSub1 = document.frmHarvestForm.cboSub1.options[document.frmHarvestForm.cboSub1.selectedIndex].value; var iSub2 = document.frmHarvestForm.cboSub2.options[document.frmHarvestForm.cboSub2.selectedIndex].value; var dtBeginDate = document.frmHarvestForm.txtBeginDate.value; var dtEndDate = document.frmHarvestForm.txtEndDate.value; var iIndCert = document.frmHarvestForm.cboIndCert.value; location.replace("HarvestBoard.asp?cboSource="+iSource+"&cboSub1=0&cboSub2=0&cboSub3=0&txtBeginDate="+dtBeginDate+"&txtEndDate="+dtEndDate+"&cboIndCert="+iIndCert); } function cboSub1Change(){ var iSource = document.frmHarvestForm.cboSource.options[document.frmHarvestForm.cboSource.selectedIndex].value; var iSub1 = document.frmHarvestForm.cboSub1.options[document.frmHarvestForm.cboSub1.selectedIndex].value; var dtBeginDate = document.frmHarvestForm.txtBeginDate.value; var dtEndDate = document.frmHarvestForm.txtEndDate.value; var iIndCert = document.frmHarvestForm.cboIndCert.value; location.replace("HarvestBoard.asp?cboSource="+iSource+"&cboSub1="+iSub1+"&cboSub2=0&cboSub3=0&txtBeginDate="+dtBeginDate+"&txtEndDate="+dtEndDate+"&cboIndCert="+iIndCert); } function cboSub2Change(){ var iSource = document.frmHarvestForm.cboSource.options[document.frmHarvestForm.cboSource.selectedIndex].value; var iSub1 = document.frmHarvestForm.cboSub1.options[document.frmHarvestForm.cboSub1.selectedIndex].value; var iSub2 = document.frmHarvestForm.cboSub2.options[document.frmHarvestForm.cboSub2.selectedIndex].value; var dtBeginDate = document.frmHarvestForm.txtBeginDate.value; var dtEndDate = document.frmHarvestForm.txtEndDate.value; var iIndCert = document.frmHarvestForm.cboIndCert.value; location.replace("HarvestBoard.asp?cboSource="+iSource+"&cboSub1="+iSub1+"&cboSub2="+iSub2+"&cboSub3=0&txtBeginDate="+dtBeginDate+"&txtEndDate="+dtEndDate+"&cboIndCert="+iIndCert); } function cboSub3Change(){ var iSource = document.frmHarvestForm.cboSource.options[document.frmHarvestForm.cboSource.selectedIndex].value; var iSub1 = document.frmHarvestForm.cboSub1.options[document.frmHarvestForm.cboSub1.selectedIndex].value; var iSub2 = document.frmHarvestForm.cboSub2.options[document.frmHarvestForm.cboSub2.selectedIndex].value; var iSub3 = document.frmHarvestForm.cboSub3.options[document.frmHarvestForm.cboSub3.selectedIndex].value; var dtBeginDate = document.frmHarvestForm.txtBeginDate.value; var dtEndDate = document.frmHarvestForm.txtEndDate.value; var iIndCert = document.frmHarvestForm.cboIndCert.value; location.replace("HarvestBoard.asp?cboSource="+iSource+"&cboSub1="+iSub1+"&cboSub2="+iSub2+"&cboSub3="+iSub3+"&txtBeginDate="+dtBeginDate+"&txtEndDate="+dtEndDate+"&cboIndCert="+iIndCert); } hi again hi i want to create a form Form have 2 submit buttons also have one drop down list when selecting dropdown list item disable the one submit button plzzzzzz help m for do this with sample code needed. 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 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 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> 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. 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.
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 This script works great in Google Chrome, mac, firefox >> BUT NOT WORKING IN IE <script type="text/javascript"> // Get value for second dropdown var request = false; if (!request && typeof XMLHttpRequest != 'undefined') { request = new XMLHttpRequest(); } function fillSelect(groups) { var url = "csa_ajax.php?groups=" + escape(groups); request.open("GET", url, true); request.onreadystatechange = go; request.send(null); } function go() { if (request.readyState == 4) { if (request.status == 200) { var response = request.responseText; var list=document.getElementById("groupitems"); var items=response.split('|'); for (i=1; i<items.length; i++) { var values=items[ i ].split(';'); var x=document.createElement('option'); x.setAttribute('value', values[0]); var y=document.createTextNode(values[1]); x.appendChild(y); list.appendChild(x); }}}} function initCs() { var groups=document.getElementById('groups'); groups.onchange=function() { if(this.value!="") { var list=document.getElementById("groupitems"); while (list.childNodes[0]) { list.removeChild(list.childNodes[0]) } fillSelect(this.value); } } fillSelect(groups.value); } window.onload=initCs; </script> <script type="text/javascript"> // pass selected value to textboxes function SplitText (info) { if (info == '') { return; } var tarr = info.split(","); document.getElementById('tBox1').value = tarr[0]; document.getElementById('tBox2').value = tarr[1]; document.getElementById('tBox3').value = tarr[2]; document.getElementById('tBox4').value = tarr[3]; } </script> <form method="post" action="#"> <p><label>groups: <select id="groups" name="groups"> <option>===Select Group ===</option> <?php require_once("includes/connect.php"); $mysql = mysql_query("SELECT * FROM qw_groups"); while($group=mysql_fetch_assoc($mysql)){ echo "<option value='$group[id]'>$group[GroupName]</option>"; } echo "</select>"; ?> </label> <label>GroupItems: <select id='groupitems' name='groupitems' onChange="SplitText(this.value)" onClick="SplitText(this.value)"> <option>===Select Group Item===</option> </select></label></p> <!-- Input selected data from listBox --> <p style="margin: 2px"> <input type="text" name="GroupId" id="tBox1" value=""><br> <input type="text" name="GroupName" id="tBox2" value=""><br> <input type="text" name="GroupItemId" id="tBox3" value=""><br> <input type="text" name="GroupItem" id="tBox4" value=""><br> </p> </form> <!-- here is the PHP. page csa_ajax.php --> <?php require_once("includes/connect.php"); $groups=@$_GET[groups]; $q = mysql_query("SELECT * FROM qw_groupitems WHERE GroupId = '$groups'"); { while ($r = mysql_fetch_assoc($q)){ $f1 = $r[GroupId]; $f2 = $r[GroupName]; $f3 = $r[id]; $f4 = $r[GroupItem]; echo "|$f1,$f2,$f3,$f4;$f1-$f4"; } } ?> 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 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 have DropdwonList with elements, 1,2,3 and 4.. and I have another DropdownList with options Normal, Standard, Emegency, and Expendited. Can you help me with a code, so that when I select "1" option on the first dropdown, the "Emegency" option on the second dropdown is set/selected. Thanks in advance 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 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. <!-- *** NOTE:*** I EDITED THIS SCRIPT WITH YOUR SUGGESTION *** --> <!-- *** THE SCRIPT IS STILL NOT WORKING *** --> ALSO: Would the second drop down need to be in <?php tags - or is it being populated with just "java" <!-- *** THE FIRST DROPDOWN GETS THE DATA FROM (db)qw_groups BUT DOES NOT "@GET" and pass the value to qw_groupitems *** --> <!-- *** first dropdown value=$group[id] *** --> <!-- *** Then second dropdown should populate with: $q = mysql_query("SELECT * FROM qw_groupitems WHERE GroupId ='$groups'"); *** --> <!-- *** the .php code listed below, the page is: csa_ajax.php *** --> <script type="text/javascript"> var request = false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { request = false; } } @end @*/ if (!request && typeof XMLHttpRequest != 'undefined') { request = new XMLHttpRequest(); } function fillSelect(groups) { var url = "csa_ajax.php?groups=" + escape(groups); request.open("GET", url, true); request.onreadystatechange = go; request.send(null); } function go() { if (request.readyState == 4) { if (request.status == 200) { var response = request.responseText; var list=document.getElementById("groupitems"); var items=response.split('|'); for (var i=1; i<items.length; i++ ) { var x = document.createElement('option'); var y = items[i]; x.text = x.value = y; list.appendChild(x); } } } } function initCs() { var groups=document.getElementById('groups'); groups.onchange=function() { if(this.value!="") { var list=document.getElementById("groupitems"); while (list.childNodes[0]) { list.removeChild(list.childNodes[0]) } fillSelect(this.value); } } fillSelect(groups.value); } window.onload=initCs; </script> <form method="post" action="#"> <p><label>groups: <select id="groups" name="groups"> <?php require_once("includes/connect.php"); $mysql = mysql_query("SELECT * FROM qw_groups"); while($group=mysql_fetch_assoc($mysql)){ echo "<option value='$group[id]'>$group[GroupName]</option>"; } echo "</select>"; ?> </label> <label>GroupItems: <select id='groupitems' name='groupitems'> <option> == Select Group== </option> </select></label></p> </form> <!-- *** HERE IS THE PHP PAGE csa_ajax.php ***--> <?php require_once("includes/connect.php"); $groups=@$_GET['groups']; $q = mysql_query("SELECT * FROM qw_groupitems WHERE GroupId ='$groups'"); while ($r = mysql_fetch_assoc($q)){ echo "|".$r['GroupId']; } } ?> Ok i have a question. Is there any way to short down the drop down in "Alphabetical" order. I have a drop down select list which gets its values from mysql DB and i want it to sort it down in alphabetical order to easy selection for the user. Thanks in advance. I need help with this js... this is dropdown list...if user choose okc in first list(vrsta) in second (celik) user can choose C0270 and C0370...if chosen pc in first list in second user can choose C1330 and C1530 etc... There are two boxes...ans15 and ans14...and button which user clicks The idea is that user choose one option(okc,pc or cc) and choose option (C0270 or something else) onclick some values should be written in boxes example: chosen okc and C0270 in ans15 "hello" and in ans14 "goodbye" should be writen if chosen okc and C0370 in ans15 "hi" and in ans14 "bye" should be writen Code: <script type="text/javascript"> function setOptions(chosen) { var izbor = document.form3.celik; izbor.options.length = 0; if (chosen == " ") { izbor.options[izbor.options.length] = new Option('choose',' '); } if (chosen == "okc") { izbor.options[izbor.options.length] = new Option('C0270','C0270'); izbor.options[izbor.options.length] = new Option('C0370','C0370'); } if (chosen == "pc") { izbor.options[izbor.options.length] = new Option('C1330','C1330'); izbor.options[izbor.options.length] = new Option('C1530','C1530'); } if (chosen == "cc") { izbor.options[izbor.options.length] = new Option('C1120','C1120'); izbor.options[izbor.options.length] = new Option('C1220','C1220'); } } </script> </head> <body> <FORM name="form3"> <table width="439" height="139" border="1"> <tr> <td width="200" height="33"> <div align="center"> <select name="vrsta" size="1" onchange="setOptions(document.form3.vrsta.options [document.form3.vrsta.selectedIndex].value);"> <option value=" " selected="selected"> </option> <option value="okc">Opsti konstrukcijski celici</option> <option value="pc">Poboljsani celici</option> <option value="cc">Cementirani celici</option> <option value="cl">Celicni liv</option> <option value="sl">Sivi liv</option> </select> <br> <br> </div></td> <td width="108" rowspan="3"> </td> <td width="109" rowspan="3"> </td> </tr> <tr> <td height="33"><div align="center"> <select name="celik" size="1"> <option value=" " selected="selected">Izabrati prvo vrstu</option> </select> </div></td> </tr> <tr> <td height="23" rowspan="2"><div align="center"> <input type="button" value=" ok " onclick="beta(this.form)" /> </div> </div> <div align="center"></div> </td> </tr> <tr> <td><input type="type" "number" value="" name="ans15" size="9" /></td> <td><input type="type" "number" value="" name="ans14" size="9" /></td> </tr> </table> </FORM> </body> </html> |