www.webdeveloper.com
Results 1 to 10 of 10

Thread: Drop Down Menu -- when selection made automatically taken to page w/ out pressing GO

  1. #1
    Join Date
    Sep 2003
    Posts
    59

    Question Drop Down Menu -- when selection made automatically taken to page w/ out pressing GO

    Ive seen this many times, and i need this for my site. In a drop down menu, when you select an option, I want it to automatically take you to the page without pressing 'Go'. I have viewed sources with pages that have this feature and I have a feeling it has to do with an 'onchange' I am seeing in the select tags. if so... i have no idea how to use it. can someone please help me?

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You could use something like this:

    Code:
    <form action="">
    	<p><select onchange="window.location.href=this.options[this.selectedIndex].value">
    		<option value="http://www.w3c.org">W3C</option>
    		<option value="http://www.webdevfaqs.com">Web Dev FAQs</option>
    	</select></p>
    </form>
    Though you should combine it with a PHP or Perl script to keep it working for those without JavaScript enabled...

  3. #3
    Join Date
    Sep 2003
    Posts
    59
    is there anything in the onchange that i need to edit?

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Nope... But like I said, does your server support either PHP or Perl to use as a backup, or do you have an alternate, accessible way to access those pages?

  5. #5
    Join Date
    Sep 2003
    Posts
    59
    I have no clue... my server supports php i know that. i use plesk 6.0 if that helps

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Ok, then, here's what you want:

    PHP Code:
    <?PHP
    if (isset($_POST['submit'])) {
        
    header("Location:".$_POST['loc']);
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>The Accessible Way...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
        <p><select name="loc" onchange="window.location.href=this.options[this.selectedIndex].value">
            <option value="http://www.w3c.org">W3C</option>
            <option value="http://www.webdevfaqs.com">Web Dev FAQs</option>
        </select>
        <input type="submit" name="submit" value="Go"></p>
    </form>
    </body>
    </html>

  7. #7
    Join Date
    Sep 2003
    Posts
    59
    thanks. i havent put that on there yet but now i have another problem. my whole website loads in an iframe (you can go check it out at www.playingwithfaeries.com) .. now the page that i am using this feature on is at www.playingwithfaeries.com/PetColours.htm . if you goto the page the script works perfectly... but when you goto it from the link on my site (its under guides in the link called 'Pet Colours) it doesnt work... at least not for me. Is that becuase i dont have the php on there yet , or maybe does it have to do that becuase it loaded in another iframe? or is there something else... thanks!
    Last edited by GreyFaerie; 10-10-2003 at 07:31 AM.

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You'll want to use self.location.href instead of window.location.href...

  9. #9
    Join Date
    Sep 2003
    Posts
    59
    can you tell me exactly what i need to edit on the php?

    this is what i am seeing :
    'submit' - ??
    "Location:" - "iframe name":
    'loc' - ???
    'PHP_SELF" - php file name

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    With a PHP header redirect, you won't be able to direct the individual frame...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles