/* This script and many more are available free online at The JavaScript Source :: http://javascript.internet.com Created by: Down Home Consulting :: http://downhomeconsulting.com */ /* Night Club Drop Downs v1.0. (c) Copyright 2005 Down Home Consulting, Inc. www.DownHomeConsulting.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, itness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. */ // If you have PHP you can set the post values like this //var postClub = ''; //var postNight = ''; var postClub = ''; var postNight = ''; // Club table // // To edit the list, just delete a line or add a line. Order is important. // The order displayed here is the order it appears on the drop down. // var Club = '\ Thursday:Tribe Hyperclub:Tribe Hyperclub|\ Thursday:SeVen Nightclub:SeVen Nightclub|\ Thursday:1234:1234|\ Friday:SeVen Nightclub:SeVen Nightclub|\ Friday:Tribe Hyperclub:Tribe Hyperclub|\ Saturday:SeVen Nightclub:SeVen Nightclub|\ Saturday:Tribe Hyperclub:Tribe Hyperclub (21+)|\ '; // Night data table // // To edit the list, just delete a line or add a line. Order is important. // The order displayed here is the order it appears on the drop down. // var Night = '\ Thursday:Thursday, November 27th|\ Friday:Friday, November 21st|\ Saturday:Saturday, November 22nd|\ '; function TrimString(sInString) { if ( sInString ) { sInString = sInString.replace( /^\s+/g, "" );// strip leading return sInString.replace( /\s+$/g, "" );// strip trailing } } // Populates the Night selected with the counties from the Night list function populateNight(defaultNight) { if ( postNight != '' ) { defaultNight = postNight; } var NightLineArray = Night.split('|'); // Split into lines var selObj = document.getElementById('NightSelect'); selObj.options[0] = new Option('Select Night',''); selObj.selectedIndex = 0; for (var loop = 0; loop < NightLineArray.length - 1; loop++) { lineArray = NightLineArray[loop].split(':'); NightCode = TrimString(lineArray[0]); NightName = TrimString(lineArray[1]); if ( NightCode != '' ) { selObj.options[loop + 1] = new Option(NightName, NightCode); } if ( defaultNight == NightCode ) { selObj.selectedIndex = loop + 1; } } } function populateClub() { var selObj = document.getElementById('ClubSelect'); var foundClub = false; // Empty options just in case new drop down is shorter if ( selObj.type == 'select-one' ) { for (var i = 0; i < selObj.options.length; i++) { selObj.options[i] = null; } selObj.options.length=null; selObj.options[0] = new Option('Select Club',''); selObj.selectedIndex = 0; } // Populate the drop down with Clubs from the selected Night var ClubLineArray = Club.split("|"); // Split into lines var optionCntr = 1; for (var loop = 0; loop < ClubLineArray.length; loop++) { lineArray = ClubLineArray[loop].split(":"); NightCode = TrimString(lineArray[0]); ClubCode = TrimString(lineArray[1]); ClubName = TrimString(lineArray[2]); if (document.getElementById('NightSelect').value == NightCode && NightCode != '' ) { // If it's a input element, change it to a select if ( selObj.type == 'text' ) { parentObj = document.getElementById('ClubSelect').parentNode; parentObj.removeChild(selObj); var inputSel = document.createElement("SELECT"); inputSel.setAttribute("name","Club"); inputSel.setAttribute("id","ClubSelect"); parentObj.appendChild(inputSel) ; selObj = document.getElementById('ClubSelect'); selObj.options[0] = new Option('Select Club',''); selObj.selectedIndex = 0; } if ( ClubCode != '' ) { selObj.options[optionCntr] = new Option(ClubName, ClubCode); } // See if it's selected from a previous post if ( ClubCode == postClub && NightCode == postNight ) { selObj.selectedIndex = optionCntr; } foundClub = true; optionCntr++ } } } function initNight(Night) { populateNight(Night); populateClub(); }