PDA

View Full Version : Chain Select Menu Enhancement



Kains
12-01-2016, 09:08 PM
1) Script Title: Chained Select Menu

2) Script URL (on DD): http://dynamicdrive.com/dynamicindex1/chainedmenu/index.htm

3) Describe problem: Is it possible to make the each selection open a predefined URL? I have this so far ...


<form action="detail.php" onchange="loadPage(this.value)">
<select name="query" style="width:100%;"></select>
<select name="query2" style="width:100%;" ></select>
<select name="query3" style="width:100%;" ></select>
<input type="button" value="Reset" onclick="resetListGroup('vehicles')">
<input type="submit" value="Search">
</form>

<script type="text/javascript">
function loadPage(url)
{
location.href = url;
}
</script>

But I have no idea how to go further with it? The kind URL I would like to run each time a user selects would be


detail.php?query= (first menu choice)

and then


detail.php?query2= (2nd menu choice)

and so on.

Thanks

ddadmin
12-08-2016, 11:06 PM
The function that's responsible for taking the final selected OPTION"s value attribute and redirecting the user to that value as a URL is the folliowing inside chanedmenu.js:


function goListGroup(){
for (i=arguments.length-1;i>=0; i--){
if (arguments[i].selectedIndex!=-1){
var selectedOptionvalue=arguments[i].options[arguments[i].selectedIndex].value
if (selectedOptionvalue!=""){
if (onclickaction=="alert")
alert(selectedOptionvalue)
else if (newwindow==1)
window.open(selectedOptionvalue)
else
window.location=selectedOptionvalue
break
}
}
}
}

This is untested, but try modifying the above to:


function goListGroup(){
for (i=arguments.length-1;i>=0; i--){
if (arguments[i].selectedIndex!=-1){
var selectedOptionvalue=arguments[i].options[arguments[i].selectedIndex].value
if (selectedOptionvalue!=""){
alert('detail.php?query2=' + selectedOptionvalue) // change alert to location= to redirect
}
}
}
}

This should alert the value "detail.php?query2=" PLUS the selected OPTION"s value attribute value. When you want it to redirect instead, just change alert() to location=