PDA

View Full Version : dynamic drive ajax tabs - dropdown



nikomou
05-07-2009, 09:01 AM
Script Name: Ajax Tabs Content Script (v 2.2)
Script URL: http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/


<!--Load "canada.htm" into the the Ajax Tabs Content Container -->
<a href="javascript:countries.loadjaxpage('canada.htm')">Load New Page</a>

I want do load a page using a drop down menu, i've tried this, but it doesnt seem to work! anybody got any ideas? thanks


<option value="something" onChange="javascript:countries.loadjaxpage('canada.htm')">Something</option>

ddadmin
05-08-2009, 01:15 AM
I assume you're trying to run the function loadajaxpage() inside a SELECT drop down menu? What you have won't work since the JavaScript syntax is incorrect. For example, onChange can't be added inside the OPTION element, it has no effect. Here's an example that should work:


<form id="aform">
<select id="mymenu" size="1">
<option value="nothing">Select a page</option>
<option value="canada.htm">Canada</option>
<option value="china.htm">China</option>
<option value="usa.htm">USA</option>
</select>
</form>

<script type="text/javascript">

var selectmenu=document.getElementById("mymenu")
selectmenu.onchange=function(){ //run some code when "onchange" event fires
var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
if (chosenoption.value!="nothing"){
countries.loadajaxpage(chosenoption.value)
}
}

</script>

You may want to read up on how to manipulate SELECT menus in JavaScript (http://www.javascriptkit.com/jsref/select.shtml).