I think he means that he does *NOT* want to have to write the [icode] ... onchange="..."...[/icpde] and that he wants the onchange event to automatically be added on all pages.
SAMUVK: If indeed that is what you mean, I'd suggest using a CSS class name to indicate which <select>s you want to attach the code to.
Code:
<select class="urlSelector">
...
</select>
And then have a "urlSelector.js" file that you include on each page.
If you include the file *JUST BEFORE* the </body> of the page you can make it completely unobtrusive.
In other words, your overall page might be something like:
Code:
<html>
<head>
...
</head>
<body>
...
<select class="urlSelector">
<option>Select an option</option>
<option value="http://www.google.com?q=orange">Orange</option>
<option value="http://www.google.com?q=pineapple">Pineapple</option>
<option value="http://www.google.com?=banana">Banana</option>
</select>
...
<script type="text/javascript" src="urlSelector.js"></script>
</body>
</html>
And then the contents of your
urlSelector.js file (or whatever you choose to name it) could be something like this:
Code:
(
function( ) /* anonymous master function
{
var sels = document.getElementsByTagName("select");
for ( var s = 0; s < sels.length; ++s )
{
var sel = sels[s];
if ( sel.className.indexOf("urlSelector") >= 0 )
{
sel.onchange=changeURL;
}
}
function changeURL( )
{
var url = this.value;
if ( url != "" ) location.href = url;
}
} // end of master function
)(); // self-invoke master function
Lots of other ways to skin this particular cat, but one advantage of this one is that you could have two or more such <select>s on any HTML page, if desired.