function CreateTuningSelector() { $("#Instrument").change(function() { var str = ""; var instrument = ""; $("#Instrument option:selected").each(function() { instrument = $(this).text(); if (instrument == "Guitar") { str = ""; }; if (instrument == "4-string Banjo") { str = ""; }; if (instrument == "5-string Banjo") { str = ""; }; if (instrument == "Ukelele") { str = ""; }; }); $("#Tunings").html(str); CreateCustomTuningSelector(); AssembleFormTuning(); }) .trigger('change'); } function CreateCustomTuningSelector() { $("#TuningSelector").change(function() { var str = ""; var instrument = ""; var value = ""; $("#TuningSelector option:selected").each(function() { value = $(this).val(); if (value == "Custom") { $("#Instrument option:selected").each(function() { instrument = $(this).val(); }); if (instrument == "Guitar") { str = ""; }; if (instrument == "4-string Banjo") { str = ""; }; if (instrument == "5-string Banjo") { str = ""; }; if (instrument == "Ukelele") { str = ""; }; }; }); $("#TuningPositions").html(str); }) .trigger('change'); } function AssembleFormTuning() { //Create a hidden field with the correct Tuning, if tuning = "Custom", assemble the custom tuning. $("input").click(function() { var str = ""; $("#TuningSelector option:selected").each(function() { var value = $(this).val(); if (value == "Custom") { var arr = new Array(); $(".TuningInput").each(function() { str = $(this).val(); arr.push(str); }); str = arr.join("-"); } else { str = $(this).val(); }; }); var htmlStr = "" $("#HiddenTuningInput").html(htmlStr); }); } $(document).ready(function() { CreateTuningSelector(); });