JavaScript - Triple Combo Box And Selected Values
Hi All,
I'm using Philip M's great Javascript tutorial "Triple Combo Box" to populate three combo boxes on my site. The problem i'm having is that I use the combo boxes to allow users to submit a DB search request using GET Form and I need to have the submitted parameters "selected" when the search result page loads. I've searched all over the internet and I can't seem to find a usable solution so any help would be GREATLY appreciated. Thanks! If you need more information, lemme know! Nick Similar TutorialsI have been working with the double combo box w/ description script from javascriptkit, and I attempted to add an additional 3rd combo box that would switch selects based upon selection of the 2nd combo box, but I am having difficulty with this. Any help would be appreciated. Here is the code: Code: <script language="JavaScript"> <!-- //Double Combo Box with Description Code- by Randall Wald (http://www.rwald.com) //Visit JavaScript Kit (http://javascriptkit.com) for script //Credit must stay intact for use var num_of_cats = 4; // This is the number of categories, including the first, blank, category. var open_in_newwindow=1; //Set 1 to open links in new window, 0 for no. var option_array = new Array(num_of_cats); option_array[0] = new Array("You need to select a category"); // This is the first (blank) category. Don't mess with it. option_array[1] = new Array("-- Select One --", "JavaScript Kit", "News.com", "Wired"); option_array[2] = new Array("-- Select One --", "CNN", "ABC News"); option_array[3] = new Array("-- Select One --", "Google", "Ask Jeeves"); var text_array = new Array(num_of_cats); text_array[0] = new Array("Here's how you use this box: First, you select a category in the Category drop-down. Then, select a link from the Link drop-down. Then, read the description in this box, or click Go to go to the page. If you ever need to see this help again, just go back to the top option in the Category box."); // These are general instructions. Change them if you want, or keep them if you don't. text_array[1] = new Array("These are some of my favorite technology sites. You should visit them.", // Note that the first entry here is a general description of this category. After than, they're descriptions of each link. Make sure that you don't put the first link first; the general description must be first. "This is a page with a bunch of nice JavaScripts that you can use. They also have tutorials in all sorts of subjects.", "CNet news. If it's in technology, it's in here.", "Wired magazine is the type of magazine which needs no introduction."); text_array[2] = new Array("These days, it's important to keep up on the news. These sites will help you do that.", "CNN. What list of news sites would be complete without it?", "Here, you can get links to World News Tonight, or see video clips."); text_array[3] = new Array("If you can't find it via other means, you'll need to find it with a search engine. These are some of the best.", "Undoubtedly, the best search engine out there.", "Their natural-language search sometimes comes up with results you won't get with other engines."); var url_array = new Array(num_of_cats); url_array[0] = new Array("#"); // The first category. This should have no items other than "#". url_array[1] = new Array("#", // The second category; the first "real" category. Note the initial #. That is the category which says "Please select a link." It doesn't need a URL. Start putting the other URL's in after that first line. "http://javascriptkit.com/", "http://www.news.com/", "http://www.wired.com/"); url_array[2] = new Array("#", "http://www.cnn.com/", "http://abcnews.go.com/"); url_array[3] = new Array("#", "http://www.google.com/", "http://www.aj.com/"); function switch_select() { for (loop = window.document.form_1.select_2.options.length-1; loop > 0; loop--) { window.document.form_1.select_2.options[loop] = null; } for (loop = 0; loop < option_array[window.document.form_1.select_1.selectedIndex].length; loop++) { window.document.form_1.select_2.options[loop] = new Option(option_array[window.document.form_1.select_1.selectedIndex][loop]); } window.document.form_1.select_2.selectedIndex = 0; } function switch_text() { window.document.form_1.textarea_1.value = text_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex]; } function box() { if (window.document.form_1.select_2.selectedIndex == 0) { alert("Where do you think you're going?"); } else { if (open_in_newwindow==1) window.open(url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex],"_blank"); else window.location=url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex] } } function set_orig() { window.document.form_1.select_1.selectedIndex = 0; window.document.form_1.select_2.selectedIndex = 0; } window.onload=set_orig // --> </script> <form name="form_1" onSubmit="return false;"> <textarea WRAP="virtual" name="textarea_1" rows=6 cols=60>Here's how you use this box: First, you select a category in the Category drop-down. Then, select a link from the Link drop-down. Then, read the description in this box, or click Go to go to the page. If you ever need to see this help again, just go back to the top option in the Category box.</textarea><br /> <!-- This should be the same as the general instructions in the above code. --> <select name="select_1" onChange="switch_select(); switch_text();"> <option>-- Categories --</option> <option>Technology Sites</option> <option>News Sites</option> <option>Search Engines</option> </select> <select name="select_2" onChange="switch_text();"> <option>You need to select a category</option> <option> </option> <option> </option> </select> <input type="submit" onClick="box();" value="Go!"> </form> <p align="center">This free script provided by<br /> <a href="http://javascriptkit.com">JavaScript Kit</a></p> Hi, Gang - This is my first time posting. I'm a JavaScript noob - I think I've figured out what direction to take - just not sure how to get there. I have a triple drop down select menu. I want the third(final) selection to reveal a hidden div. Am I on the right track by thinking I need to use a combination of onchange, getElementById and if statements? The javascript code for the dropdown is Philip M's Cut & Paste Triple Combo box from JavaScriptKit.com. That work's beautifully. I won't insert my exact code as the category list is significantly longer. Code: var categories = []; categories["startList"] = ["Wearing Apparel","Books"] categories["Wearing Apparel"] = ["Men","Women","Children"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = ["How-To","Travel","Cookbooks", "Old Churches"]; var nLists = 3; // 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['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['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 getValue(L3, L2, L1) { alert("Your selection was:- \n" + L1 + "\n" + L2 + "\n" + L3); } function init() { fillSelect('startList',document.forms['tripleplay']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> My HTML is: Code: <div id="menuSearch"> <form name="tripleplay" action=""> <p><select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>-- Topic of Interest --</option> </select></p> <p><select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>-- Geographic Area --</option> </select></p> <select id="info"name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >-- Information Type --</option> </select> </form> </div> the divs to show/hide a Code: <div id="modelingCV">list of publications</div> <div id="groundwaterCV">list of publications</div> <div id="subsidenceCV">list of publications</div> <div id="managementCV">list of publications</div> <div id="qualityCV">list of publications</div> <div id="wildlifeCV">list of publications</div> Is replacing the getValue in the onchange in the final form select with getElementByID the best approach? And replace the getValue in the javascript function with some type of if statement to specify the values? I am guessing I need to hide the divs with javascript vs CSS? Am I completely off base all around? Oy. Definitely bit off more than I can chew on this one. Any guidance would be appreciated. Thanks for reading! i wud like to grab the values for the selected item in the last combobox n insert it into a form. thanks in advance 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> <script type="text/javascript"> // first combo box data_1 = new Option("1", "$"); data_2 = new Option("2", "$$"); // second combo box data_1_1 = new Option("11", "-"); data_1_2 = new Option("12", "-"); data_2_1 = new Option("21", "--"); data_2_2 = new Option("22", "--"); data_2_3 = new Option("23", "--"); data_2_4 = new Option("24", "--"); data_2_5 = new Option("25", "--"); // third combo box data_1_1_1 = new Option("111", "1"); data_1_1_2 = new Option("112", "2"); data_1_1_3 = new Option("113", "3"); data_1_2_1 = new Option("121", "4"); data_1_2_2 = new Option("122", "5"); data_1_2_3 = new Option("123", "6"); data_1_2_4 = new Option("124", "7"); data_2_1_1 = new Option("211", "8"); data_2_1_2 = new Option("212", "9"); data_2_2_1 = new Option("221", "10"); data_2_2_2 = new Option("222", "11"); data_2_3_1 = new Option("231", "12"); data_2_3_2 = new Option("232", "13"); // other parameters displaywhenempty="" valuewhenempty=-1 displaywhennotempty="-select-" valuewhennotempty=0 function change(currentbox) { numb = currentbox.id.split("_"); currentbox = numb[1]; i=parseInt(currentbox)+1 // I empty all combo boxes following the current one while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) && (document.getElementById("combo_"+i)!=null)) { son = document.getElementById("combo_"+i); // I empty all options except the first one (it isn't allowed) for (m=son.options.length-1;m>0;m--) son.options[m]=null; // I reset the first option son.options[0]=new Option(displaywhenempty,valuewhenempty) i=i+1 } // now I create the string with the "base" name ("stringa"), ie. "data_1_0" // to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill stringa='data' i=0 while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) && (document.getElementById("combo_"+i)!=null)) { eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex") if (i==currentbox) break; i=i+1 } // filling the "son" combo (if exists) following=parseInt(currentbox)+1 if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) && (document.getElementById("combo_"+following)!=null)) { son = document.getElementById("combo_"+following); stringa=stringa+"_" i=0 while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) { // if there are no options, I empty the first option of the "son" combo // otherwise I put "-select-" in it if ((i==0) && eval("typeof("+stringa+"0)=='undefined'")) if (eval("typeof("+stringa+"1)=='undefined'")) eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)") else eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)") else eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)") i=i+1 } //son.focus() i=1 combostatus='' cstatus=stringa.split("_") while (cstatus[i]!=null) { combostatus=combostatus+cstatus[i] i=i+1 } return combostatus; } } //--> </script> </head> <body> <form> <select name="combo0" id="combo_0" onChange="change(this);" style="width:200px;"> <option value="value1">-select-</option> <option value="value2">1</option> <option value="value3">2</option> </select> <BR><BR> <select name="combo1" id="combo_1" onChange="change(this)" style="width:200px;"> <option value="value1"> </option> </select> <BR><BR> <select name="combo2" id="combo_2" onChange="change(this);" style="width:200px;"> <option value="value1"> </option> </select> <BR><BR> </form> </body> </html> I tried implementing a cleaner approach to a web form I had created, but it doesn't seem to be passing the values to the server properly. What gives? This form on the left and right work perfectly, but they have two ridiculously long drop down lists, which would be the "ProgramOfInterest" fields (please use the following values preselected in this form) http://www.nationalcollegesearch.org..._pingpost.html On this form, I tried creating a triple drop down list setup to clean up the older, long lists in this example, but it doesn't pass the values properly. It also seems to not duplicate the new drop down triple drop lists properly as in the original form. You can change the values in the drop downs in the forms to see what I mean. Also just pick Bachelor's > B_Business > Business Administration in the triple drop downs for an example since I don't know how to preselect those values. http://nationalcollegesearch.org/Integrate/PleaseHelpMeWithMyCode/integrate_pingpost_experiment.html Please let me know if there is anything I can do to pass the correct values to the server. Thanks! P.S. Please note that I have disabled the form on the right and intentionally left the action empty. This is the triple drop down script I am using: Code: <script type="text/javascript"> /* Triple Combo Script Credit By Philip M: http://www.codingforums.com/member.php?u=186 Visit http://javascriptkit.com for this and over 400+ other scripts Modified by: jmrker */ var categories = []; categories["startList"] = ["Diploma/Certificate:CE","Associate's:AA","Bachelor's:BA","Master's:MA"]; categories["Diploma/Certificate"] = ["C_Arts & Humanities:CE1","C_Automotive:CE2","C_Computers & IT:CE3","C_Education & Teaching:CE4","C_Health & Medical:CE5","C_Trades & Careers:CE6"]; categories["C_Arts & Humanities"] = ["Desktop Publishing:CEDP","Floral Design:CEFD","General Arts:CEGA","Interior Decorating:CEID","Jewelry:CEJ"]; categories["C_Automotive"] = ["Automotive Technician Training:CAUTO","Collision and Auto Body Repair:CCOLL","Motorcycle Mechanic Training:CMM"]; categories["C_Computers & IT"] = ["Cisco:CECS", "Information Technology:CEIT", "Microsoft:CEMS", "Network Systems:CENSYS", "Oracle:CEOR", "PC Repair:CEPC"]; categories["C_Education & Teaching"] = ["Child Day Ca CEDC", "General Education:CEGE"]; categories["C_Health & Medical"] = ["Dental Assisting:CEDENT", "Fitness:CEFIT", "Healthca CEHC", "Massage Therapy:CMT", "Medical Assisting:CEMEA", "Medical Billing and Insurance Coding:CEMBIC", "Medical Office Administration:CEMOA", "Occupation Therapy:CEOT", "Phlebotomy:CEPHL", "Social Work:CESW"]; categories["C_Trades & Careers"] = ["Administrative Assistant:CEAA", "Animal Ca CEAC", "Appliance Repair:CEAR", "Bookkeeping and Payroll Accounting:CEBOO", "Bridal Consulting:CEBC", "Carpentry and Construction:CECC", "Culinary:CECU", "Drafting:CEDR", "Electronics:CEEL", "Forestry and Wildlife:CEFW", "Gunsmithing:CEGUN", "HVAC:CEHV", "Landscaping:CELS", "Law Enforcement:CELE", " Locksmithing:CELOCK", "Plumbing and Electrical:CEPE", "Private Investigator:CEPI", "Wedding Planner:CEWP"]; categories["Associate's"] = ["A_Arts & Humanities:AA1","A_Business:AA2","A_Criminal Justice:AA3","A_Computers & IT:AA4","A_Education & Teaching:AA5","A_Health & Medical:AA6","A_Science & Technology:AA7","A_Social Sciences:AA8","A_Trades & Careers:AA9"]; categories["A_Arts & Humanities"] = ["Communication:AACOM","Fashion:AAFASH","Game Design:AAGD","General Arts:AAGA","Graphic Design:AAGR","Religion:AAREL","Web Design:AAWD","Writing:AAWR"]; categories["A_Business"] = ["Accounting:AAAC","Administrative Assistant:AAAS","Business Administration:AABA","eBusiness and eCommerece:AAEB","Finance:AAFIN","Human Resources Management:AAHR","International Business:AAIB","Marketing:AAMAR","Organizational Leadership:AAOR","Project Management:AAPM"]; categories["A_Criminal Justice"] = ["Criminal Justice:AACJ","Homeland Security:AAHS","Law:AALAW","Legal Assisting Paralegal:AAPAR","Political Science:AAPS"]; categories["A_Computers & IT"] = ["Computer Networking and Security:AACNS","Computer Science:AACS","Databases:AADB","Information Systems:AAIS","Information Technology:AAIT","Technology Management:AATEM","Web Development:AADEV"]; categories["A_Education & Teaching"] = ["Adult and Higher Education:AAHE","Curriculum and Instruction:AACI","Early Childhood Education:AAEVE","General Education:AAGE","Special Education (K-12):AASE"]; categories["A_Health & Medical"] = ["Gerontology (Study of people as they age):AAGER","Healthca AAHLTH","Healthcare Management:AAHCM","Medical Assisting:AAMA","Medical Billing and Insurance Coding:AAMBIC","Medical Office Administration:AAMOA","Nursing:AANUR","Radiology & Sonography:AARAD"]; categories["A_Science & Technology"] = ["Aviation:AAAV","Engineering Management:AAEN","Environmental Sciences:AAENV","Science:AASCI"]; categories["A_Social Sciences"] = ["Counseling:AACOUN","History:AAHIST","Psychology:AAPSY","Public Administration:AAPA","Public Safety:AAPUBS","Social Science:AASS"]; categories["A_Trades & Careers"] = ["Animal Ca AAAC","Carpentry & Construction:AACAR","Fire and Law Enforcement:AALE","Travel and Tourism:AATR"]; categories["Bachelor's"] = ["B_Arts & Humanities:BA1","B_Business:BA2","B_Computers & IT:BA3","B_Criminal Justice:BA4","B_Education & Teaching:BA5","B_Health & Medical:BA6","B_Science & Technology:BA7","B_Social Sciences:BA9","B_Trades & Careers:BA0"]; categories["B_Arts & Humanities"] = ["Communication:BACOM","Fashion:BAFASH","Game Design:BAGD","General Arts:BAGA","Graphic Design:BAGR","Music:BAMUS","Religion:BAREL","Web Design:BAWD","Writing:BAWR"]; categories["B_Business"] = ["Accounting:BAAC","Business Administration:BABA","eBusiness and eCommerece:BAEB","Entrepreneurial Studies:BAES","Finance:BAFIN","Human Resources Management:BAHR","International Business:BAIB","Marketing:BAMAR","Organizational Leadership:BAOR","Project Management:BAPM"]; categories["B_Computers & IT"] = ["Computer Networking and Security:BACNS","Computer Science:BACS","Databases:BADB","Information Systems:BAIS","Information Technology:BAIT","Technology Management:BATM","Web Development:BADEV"]; categories["B_Criminal Justice"] = ["Criminal Justice:BACJ","Homeland Security:BAHS","Law:BALAW","Legal Assisting Paralegal:BAPAR","Political Science:BAPS"]; categories["B_Education & Teaching"] = ["Adult and Higher Education:BAHE","Curriculum and Instruction:BACI","Early Childhood Education:BAECE","General Education:BAGE","Special Education (K-12):BASE"]; categories["B_Health & Medical"] = ["Gerontology (Study of people as they age):BAGR","Healthca BAHLTH","Healthcare Management:BAHCM","Medical Assisting:BAMA","Nursing:BANUR","Radiology & Sonography:BARAD"]; categories["B_Science & Technology"] = ["Aviation:BAAV","Electronics Engineering:BAEE","Engineering Management:BAEN","Environmental Sciences:BAENV","Mathematics:BAMS","Science:BASCI"]; categories["B_Social Sciences"] = ["Counseling:BACOUN","History:BAHIST","Psychology:BAPSY","Public Administration:BAPA","Public Safety:BAPUBS","Social Science:BASS","Sociology:BASOC"]; categories["B_Trades & Careers"] = ["Fire and Law Enforcement:BALE"] categories["Master's"] = ["M_Arts & Humanities:MA1","M_Business:MA2","M_Computers & IT:MA3","M_Criminal Justice:MA4","M_Education & Teaching:MA5","M_Health & Medical:MA6","M_Science & Technology:MA7","M_Social Sciences:MA9"]; categories["M_Arts & Humanities"] = ["Communication:MACOM","Game Design:MAGD","General Arts:MAGA","Graphic Design:MAGR","Music:MAMUS","Religion:MAREL","Web Design:MAWD","Writing:MAWR"]; categories["M_Business"] = ["Accounting:MAAC","Business Administration:MBA","eBusiness and eCommerece:MAED","Entrepreneurial Studies:MAES","Finance:MAFA","Finacial Planning:MAFPL","Human Resources Management:MAHR","International Business:MAIB","Marketing:MAMAR","Organizational Leadership:MAOR","Project Management:MAPM"]; categories["M_Computers & IT"] = ["Computer Networking and Security:MACNS","Computer Science:MACS","Databases:MADB","Information Systems:MAIS","Information Technology:MAIT","Technology Management:MATM","Web Development:MADEV"]; categories["M_Criminal Justice"] = ["Criminal Justice:MACJ","Homeland Security:MAHS","Law:MALAW","Legal Assisting Paralegal:MAPAR","Political Science:MAPS"]; categories["M_Education & Teaching"] = ["Adult and Higher Education:MAHE","Curriculum and Instruction:MACI","Early Childhood Education:MAECE","General Education:MAGE","Special Education (K-12):MASE"]; categories["M_Health & Medical"] = ["Gerontology (Study of people as they age):MAGR","Healthca MAHLTH","Healthcare Management:MAHCM","Medical Assisting:MAMA","Nursing:MANUR","Radiology & Sonography:MARAD"]; categories["M_Science & Technology"] = ["Aviation:MAAV","Electronics Engineering:MAEE","Engineering Management:MAEN","Environmental Sciences:MAENV","Mathematics:MAMS","Science:MASCI"]; categories["M_Social Sciences"] = ["Counseling:MACOUN","History:MAHIST","Psychology:MAPSY","Public Administration:MAPA","Public Safety:MAPUBS","Social Science:MASS","Sociology:MASOC"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.id.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['form1']['List'+i].length = 1; document.forms['form1']['List'+i].selectedIndex = 0; } var tmp = currCat.split(':'); var nCat = categories[tmp[0]]; for (each in nCat) { tmp = nCat[each].split(':'); var nOption = document.createElement('option'); var nData = document.createTextNode(tmp[0]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { var l3 = L3.split(':'); var l2 = L2.split(':'); var l1 = L1.split(':'); // alert("Your selection was:- \n" + L1 + "\n" + L2 + "\n" + L3); // alert("Your selection was:- \n" + l1[1] + "\n" + l2[1] + "\n" + l3[1]); } function init() { fillSelect('startList',document.forms['form1']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="form1" action=""> <table> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Degree:</td> <td><select id='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Select degree</option> </select> </td> </tr> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Area of Study:</td> <td><select id='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Select area of study</option> </select> </td> </tr> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Program of Interest:</td> <td><select class="frmInput" id="List3" name="ProgramOfInterest" onchange="getValue(this.value,this.form['List2'].value, this.form['List1'].value)"> <option selected >Select program</option> </select> </td> </tr> </table> </form> I have 2 combo boxes where you can move the items in combo box 1 to combo box 2. I want to validate that combo box 2 actually has something moved to it. How can I count the items in combo box 2. Combo box 2 will initially have no items in the box on page load. It is up to the user to move the items to combo box 2 and I want to make sure at least 1 item was moved.
Hi all, I have a problem here with my coding. I want to have three levels combo box. However the second level is not populating the values, therefore the third level cannot be populated also. I have attcached my codes here. Pls have a look and tell me where is my error. Thanks, Breentha Hello, I need your help. I'd like to be able to populate a combo box (drop down box) from a column in my mdb database: Ex. of whats in mdb database Name -------------- Joey Jacob Smith Jerrod Patrick What should appear in drop down: [ ==== COMBO BOX ==== ] Joey Jacob Smith Jerrod Patrick I cant seem to find any help on the web for this? Thanks for all your help in advance. My goal is that when I click on the submit button, I just want to display an alert box with the values selected, and also look at this in the console.log. Can anyone help me? Thanks. Code: <html> <head> </head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(init); function init() { $ ("#t").submit(function() { var g = showCheckedValues(); console.log(g); alert(g); }); function showCheckedValues() { // Gather all values of checked checkboxes with name "bedrooms". var checked = $('input[name=bedrooms]:checked').map(function() { return this.value; }).get(); }} </script> <body> <form id="t"> <input type="checkbox" name="bedrooms" value="1">1 bedroom<br> <input type="checkbox" name="bedrooms" value="2">2 bedroom<br> <input type="checkbox" name="bedrooms" value="3">3 bedroom<br> <input type="checkbox" name="bedrooms" value="4+">4+ bedroom<br> <input type="submit" name="save-changes"></input> </form> </body> </html> Hello I'm using the combo box selection menu by Elviro Mirko from this site (http://www.javascriptkit.com/script/...plecombo.shtml) I have made amendments to show my own data, however what I would like to happen is if the user selects from the top combo only, then all the records would be shown, whereas selecting from the second combo merely 'drills down' and shows the records required. - Hope that makes sense. The code is as follows: Code: // first combo box data_1 = new Option("Douglas - DIS", "$"); data_2 = new Option("Douglas - COE", "$$"); data_3 = new Option("Peel - DIS", "$$$"); data_4 = new Option("Peel - COE", "$$$$"); data_5 = new Option("Ramsey - DIS", "$$$$$"); data_6 = new Option("Ramsey - COE", "$$$$$$"); data_7 = new Option("Castletown - DIS", "$$$$$$$"); data_8 = new Option("Castletown - COE", "$$$$$$$$"); // second combo box data_1_1 = new Option("Registry Office Douglas", "-"); data_1_2 = new Option("Broadway Baptist Church Douglas", "-"); data_1_3 = new Option("Finch Hill Congregational Church Douglas", "-"); data_2_1 = new Option("St Thomas's Church", "--"); data_2_2 = new Option("St Barnabas Church", "--"); data_2_3 = new Option("St George's Church", "--"); The HTML code is as follows: Code: <select name="combo0" id="combo_0" onChange="change(this);" style="width:200px;"> <option value="">Select a Register...</option> <option value="Douglas - DIS">Douglas - DIS</option> <option value="Douglas - COE">Douglas - COE</option> <option value="Peel - DIS">Peel - DIS</option> <option value="Peel - COE">Peel - COE</option> <option value="Ramsey - DIS">Ramsey - DIS</option> <option value="Ramsey - COE">Ramsey - COE</option> <option value="Castletown - DIS">Castletown - DIS</option> <option value="Castletown - COE">Castletown - COE</option> </select> <BR><BR> <select name="combo1" id="combo_1" onChange="change(this)" style="width:200px;"> <option value="">Select a venue...</option> </select> the link for the actual site is http://www.manxbmd.com/cgi-bin/db.cg...m;db=marriages If you choose Douglas-COE and search, then 0 records are found, if you choose Douglas-COE followed by St Thomas's then still 0 records are found but if you search the surname Allitson you'll see that there is a record there. I'm not sure where I've gone wrong - I'm completely new to Javascript. Any suggestions welcomed. regards Pendle I have a form which contains a few drop down lists. The contents of the dropdown lists are dependent on each other and are populated via php scripts which are called each time a selection is made or changed by the user. When the view results button is clicked in the form I need the user to be directed to a specific page based on the selections they have made. The url of the page they need to be directed to is really based on what has been chosen in the first dropdown. The subsequent dropdowns form variables that I need to be sent to the page so that the data the user sees on that page is relevant. ie if the user has chosen bikes then a specific manufacturer then a specific price range the page they will be sent to will be the bike.php page with all the manufacturer specific bikes in their chosen price range visible. Can anyone tell me the best way to go about doing this please? I had thought about using the php header script along with an if statement but how do I then go about getting the variables sent to the page to be recognised? Would I be better looking at the window.location in js to do this? Any help and advice would be greatly appreciated on this. I can post the code for the form if that makes any difference. Hey javascript newbie, Im trying to figure out how to add different radio if its selected or not example: Radio_Button1 value="5": Selected Radio_Button2 value="15": Not Selected Radio_Button3 value="25": Selected Radio_Button4 value="35": Selected var addingitup = ??? and im lost???? total score from selected drop down values Hello friends the following is the code i am using without success Code: var numQuestn = 6; function GetScore(form) { var score = 0; var item = 0; var currQuestn = 0; for (i = 0; i < numQuestn; i++) { item = form.q1.selectedIndex; { score += eval(form.q1.options[item].value); } item = form.q2.selectedIndex; { score += eval(form.q2.options[item].value) } item = form.q3.selectedIndex; { score += eval(form.q3.options[item].value) } item = form.q4.selectedIndex; { score += eval(form.q4.options[item].value) } item = form.q5.selectedIndex; { score += eval(form.q5.options[item].value) } item = form.q6.selectedIndex; { score += eval(form.q6.options[item].value) } } form.total.value = score } i am not able to find the error Please help me Thank you in advance Hi Everybody This is probably a very commonly asked question, however after much searching online I can't seem to find a straightforward answer. If anyone knows the code or a link to a place with a simple example it would be great. What I have got is a form that a user has to fill out and submit (when validated all variables are stored in a session and emailed after multiple forms are completed), currently I have radio buttons, text boxes and a combo box/ drop down list (for location). All parts are working fine and validating fine. My problem is to do with the combo box//ddl. I have successfully validated the ddl so the user must select a location onsubmit and it is added to session and passed fine. At the moment the ddl only has cities or towns in it however as I would like to include different states and possibly different countries I need a code that validates the state first and then only gives the cities/towns that are in that state (otherwise my ddl would be to large). I can do this with links however I can't seem to do it in a form. I am trying to do it this way DDL has list of all states that on mouseover/ onclick the list is revealed. onclick of a specific state populates another ddl with only the cities cities/ towns that are in that state and onclick of specific city selects the location whereby onsubmit the location is stored in the the session for submission by email Thanks in advance for your help I still have the following two major issues. 1) Firstly I need to be able to send the selection from the second combo box by php. 2) secondly I need the combo box to appear within the table. (I thought this should be easy, but for the life of me cannot figure out how to get the dynamic combo into my table inside the form) I have managed to send the selection from the first combo box with the form and also I can send a selection from the second combo, however onsubmit regardless of what is selected in the second combo box it simply sends the last option not the one selected. I have spent many hours trying to figure out why this is the case to no avail. I have included my code for anyone who may be able to help. Lastly when I have figured out these 2 (with a little help) I should be able to sort out the validation by myself. Please ignore any code that is not relevant <html> <head> <script type="text/javascript"> var this1; window.onload = function() { if (!document.all) document.captureEvents(Event.CHANGE); document.getElementById('myddl').onchange = readDDL1; } function readDDL1() { var ddlobj = document.getElementById('myddl'); var currentSelection = ddlobj.options[ddlobj.options.selectedIndex].value; if (currentSelection == '') currentSelection = ddlobj.options[ddlobj.options.selectedIndex].text; doDDL2(currentSelection); } function doDDL2(ddl1Selection) { var existingDDL2; if ((existingDDL2 = document.getElementById('myddl2')) != null) existingDDL2.parentNode.removeChild(existingDDL2); var ddl2Options; switch (ddl1Selection) { case "Western Australia": ddl2Options = ["Please Select A Location", "Karratha", "Perth"]; break; case "Queensland": ddl2Options = ["Please Select A Location", "Brisbane", "Gold Coast"]; break; } if (typeof ddl2Options == "object") { ddl2 = document.createElement('select'); ddl2.id = "myddl2"; var forVar; for (forVar in ddl2Options) { var newOption = document.createElement('option'); newOption.appendChild(document.createTextNode(ddl2Options[forVar])); ddl2.appendChild(newOption); } document.body.appendChild(ddl2); } document.testform.this1.value = ((ddl2Options[forVar])); } function checkFrequency() { return ShowResults(); } function validate(){ var digits="0123456789" var temp if (document.testform.location.selectedIndex == 0) { alert("Please Select a State"); return false } if (document.testform.location2.selectedIndex == 0) { alert("Please Select a Location"); return false } return true } </script> <style type="text/css"> .td_freq { background-color:yellow; height:40px; text-align:center; } .td_sev { background-colorink; height:40px; text-align:center; } .td_wi { background-color:lightgreen; height:40px; text-align:center; } </style> </head> <body> <FORM name="testform" action='./emlapd.php' method='post' onsubmit="return checkFrequency()"> <input type='hidden' name='this1'> <table align="center" border="1" width="40%"> <tr><td><b>Current Worksite State:</b><font color="red">*</font></td> <td> <select name="location" width='53' id="myddl"> <option value="0">--- Please Select Your State --- & nbs p; & n bsp; & nbs p; </option> <option value="Western Australia">Western Australia</option> <option value="Queensland">Queensland</option> </select> </td></tr> <tr><td><b>Location:</b><font color="red">*</font></td> <td> </td></tr> </table> <tr> <th colspan="2"> <input type="submit" name='submit' value="Submit" onclick= "return validate()"> </th> <td colspan="10"> </td> <th> <input type='reset' name='reset' value='Clear Form'> </th> </tr> </table> </FORM> </body> </html> Thankyou very much to everyone that may help So I can place the DDL inside the form, however it places it at the end of the form. I want it somewhere in the middle (immediately following first combo box) My other main issue is irregardless of the selection it simply posts the last option from the DDL not the one selected. Therefore I still want the second combo box to appear immediately below the first combo box and whatever option is selected from the second combo box I want to be posted with the rest of the form data. If you have any other ideas that would be great Obviously the reason I am still getting the same incorrect post is because the variable posted is still this1 from my code which reads the last value from the DDL. I have tried with all other variables to send as well ie ddl2 however still can't seem to send the selection. So in its current state how can I send the selection and place the second DDL within the form?? Thank you like for example i have text areas named upload1 and upload2 when I click or add input on upload1 a drop down list below upload2 will not change, but when I add input on upload2 the dropdown will select "parts" Hello All, I am trying to create a three drop down lists for my job. The three drop downs would be: Degree Type (certificate, associate's, bachelor's, etc) Category (Arts & Humanities, Automotive, Computers & IT etc.) Program (Desktop Publishing, Automotive Technician Training, Network Systems, etc.) The Category list needs to be dependent on the degree type and the Program list needs to be dependent on the Category list. I need to have values that will submit to my form but ONLY for the Program List. For example: <option value="CECS">Cisco</option> <option value="CEIT">Information Technology (General)</option> <option value="CEMS">Microsoft</option> <option value="CENSYS">Network Systems</option> Please note that I must use these program codes as values and I cannot use the option name as the value. This does not have to look good, it just needs to work as it is for internal use only within my company. This form will never be used by random web surfers. If someone can point me to a tutorial for a good triple drop down that will pass ONLY the values of the third list, that would be great! Thanks! I am presently using a script provided by http://javascript.internet.com/forms...drop-down.html. This script works great, however I need three sequential drop down menus rather than the two provided in this script. I need Country > Province/State > Cities. Unfortunately I am not a programmer, but generally muddle along to a resolution. In this case I am stumped. Can anyone show me what needs to be added to that existing script to convert it into a three menu script instead of two? I've searched extensively but find nothing about this. I apologize in advance for my lack of scripting knowledge, but much of JavaScript leaves me thoroughly confused. With html I am fine, but at 69 years of age the 'newer' scripts are leaving me behind.
Dear all, Below are my current script. I need another few more sets of the triple drop down menu same as the below script... (Scenario: creating like a online shopping order form, where customers can have multiple orders.) Please guide me how to do so.. Thank you in advance. <script type="text/javascript"> /* Triple Combo Script Credit By Philip M: http://www.codingforums.com/member.php?u=186 Visit http://javascriptkit.com for this and over 400+ other scripts */ var categories = []; categories["startList"] = ["Wearing Apparel","Books"] categories["Wearing Apparel"] = ["Men","Women","Children"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = ["How-To","Travel","Cookbooks", "Old Churches"]; var nLists = 3; // 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['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['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 getValue(L3, L2, L1) { alert("Your selection was:- \n" + L1 + "\n" + L2 + "\n" + L3); } function init() { fillSelect('startList',document.forms['tripleplay']['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>Untitled Document</title> </head> <body> <form name="tripleplay" action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <select name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >Make a selection</option> </select> </form> </body> </html> |