| 
	
 | 
 Posted by Michael Winter on 02/25/06 14:13 
On 25/02/2006 09:03, Toby Inkster wrote: 
 
[snip] 
 
> Use: 
>  
> 	function formHandler () 
> 	{ 
> 		var sel = document.getElementById('site'); 
 
If one is to use the getElementById method, it should be feature tested,  
first. 
 
> 		var url = site.options[site.selectedIndex].value; 
> 		window.localtion.href = url; 
 
There are errors in both of those statements. 
 
> 	} 
 
   function formHandler() { 
     var sel, url; 
 
     if (document.getElementById 
         && (sel = document.getElementById('site')) 
         && (url = sel.options[sel.selectedIndex].value)) { 
       location.href = url; 
     } 
   } 
 
Better yet: 
 
   function goTo(sel) { 
     var url = sel.options[sel.selectedIndex].value; 
 
     if (url) { 
       location.href = url; 
     } 
   } 
 
   <select name="site" onchange="goTo(this);"> 
     <!-- ... --> 
   </select> 
 
[snip] 
 
> Now add: 
>  
> <noscript> 
>   <input type="submit" value="Go"> 
> </noscript> 
> </div> 
> </form> 
 
However, the button should be a required part of the widget[1]. 
 
[snip] 
 
Mike 
 
 
[1]    Subject: Re: how to go to a new url onChange from select 
                 box 
      Newsgroup: comp.lang.javascript 
           Date: 2004-09-22 11:50:14 GMT 
     Message-ID: opsep8lkuox13kvk@atlantis 
 
<http://groups.google.co.uk/group/comp.lang.javascript/msg/f5d0d4b48ef4056b> 
 
--  
Michael Winter 
Prefix subject with [News] before replying by e-mail.
 
  
Navigation:
[Reply to this message] 
 |