SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <select><option> to

    Code:
    <head>
    <!-- Javascript for the <select><option> html so i can redirect the user to the site. --!>
    <script type="text/javascript">
    
    parseINT(document.getElementById("menu").value);
    
    function go() 
    if(value==0) {
    window.location=document.getElementById("menu").value;
    } else {
    	print false;
    }
    </script>
    
    </head>
    
    <!--javascript ends here!--!>
    <!-- the html for the navigation --!>
    
    <div id= "navigation" >
    <table cellspacing="0" cellpadding="0" width="600">
    	<tr>
    		<td width="20&#37;">
    			<a href="link1" id="home" title="Homepage">Home</a>
    		</td>
    		<td width="20%">
    			<a href="link2" id="aboutme">About</a>
    		</td>
    		<td width="20%">
    			<a href="link3" id="blog">Blog</a>
    		</td>
    		<td width="20%">
    			<a href="link4" id="portfolio">Portfolio</a>
    		</td>
    		<td width="20%">
    
    <!-- starts the <select><option> html  --!>
    
    <select id="menu" onchange="go()">
      <option selected="yes = 1">Other</option>
      <option value="link5">W3Schools</option>
      <option value="link6">Microsoft</option>
      <option value="link7">AltaVista</option>
    </select>
    
    			</td>
    		</tr>
    	</table>
    </div>
    <!-- ends the <select> --!>
    There isn't really any problem unless it's a cross-browser compatibility problem. What i'm trying to figure out is the javascript:

    -for making the first option "Other" inactive so when you click on it, it wouldn't redirect a user to any page nor refresh the page.

    >following the conditions that: in the select list, it'll always display itself as the first option (though inactive)

    I am not really an expert javascript coder so all i did was mere coding without prior knowledge to javascript and some consulting from friends but they haven't given me a satisfactory answer (the code). So i hope some of you guys here could come forth to teach me and provide an answer to this pile of code.

    Thanks,
    Gabriel.

    #NOTES: ALL LINKS ARE REPLACED WITH LINK(VALUE) AS SITEPOINT RESTRICTS LINKS!

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function go(link) {
      if (link == "noGo") return;
      window.location = link;
    }
    Code:
    <select id="menu" onchange="go(this.value)">
      <option value="noGo" selected="selected">Other</option>
      <option value="link5">W3Schools</option>
      <option value="link6">Microsoft</option>
      <option value="link7">AltaVista</option>
    </select>
    I haven't tried it, but something like that should do the trick.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •