t_k_eoh Posted August 19, 2007 Share Posted August 19, 2007 Hi all, I read some of the postings but I still don't understand what to do on the following: I have a "Go" button and drop down list of the following: Yahoo MSN Google How do I link the Yahoo to www.yahoo.com, MSN to www.msn.com and Google to www.google.com upon pressing "Go"? The redirect will display the website on the same page. Pls advice. Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/ Share on other sites More sharing options...
NArc0t1c Posted August 19, 2007 Share Posted August 19, 2007 On you're webpage, or should it redirect to that website? if redirect to the other website, try the onclick event handler and javascript. if you want to display that website on you're webpage, try using iframes or cURL. Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328157 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 <? ob_start(); ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <select name="url"> <option value="http://www.google.co.uk" id="google">Google</option> <option value="http://www.msn.co.uk" id="msn">Msn</option> <option value="http://www.yahoo.co.uk" id="yahoo">Yahoo</option> </select> </form> <? if(isset($_POST['url'])) { header("location:".$_POST['url']); } ?> <? ob_end_flush(); ?> That should work Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328159 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 or a simple JS version! <script language=JavaScript> <!-- function Navigate() { var number = NavSelect.selectedIndex; location.href = NavSelect.options[number].value; } // --> </script> form code <select name="NavSelect" onChange="Navigate(this.form)"> <option value="" SELECTED>Click to Navigate <option value="YourPage.html">Your Page <option value="about:blank">Blank Page <option value="http://www.yoursite.com">Home </select> Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328162 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 yes, whatever you prefer. Pesonally i prefer php! Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328207 Share on other sites More sharing options...
NArc0t1c Posted August 19, 2007 Share Posted August 19, 2007 Why, the javascript example is much faster. Isn't speed what it is all about at the end of the day? Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328257 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 I dunno why well I find php easier to code that javascript my javascript never seems to work Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328262 Share on other sites More sharing options...
NArc0t1c Posted August 19, 2007 Share Posted August 19, 2007 Well, Here's a tip; You will need javascript somewhere along the line, I suggest you learn it. W3Schools has good tutorials to get you started. Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328267 Share on other sites More sharing options...
dbo Posted August 19, 2007 Share Posted August 19, 2007 Javascript is good for some things... namely user experience and prettying stuff up. Problem with it is if you rely on it for core functionality of your site and a user comes along who disables it then your site is the suck. Chances are in your case it's fine.... but beware. And never rely on it for security. Also this is a question for MadTechie: Is it best practice to do your options for a select box as you listed them or to add a closing tag? I'm not trying to play the devils advocate here I really would like to know b/c I see it as you did it a lot. I always do it like this though: <option value="1">One</option>. Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328270 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 Well i think <option value="1">One</option> is the better way, as for PHP vs. JS the way i look at it is, if its not sensitive data and then why not have the clients PC do the work for you, save the server handerling the requests.. 90% of the forms i create have JavaScripts to check the data (ie email) but i also check them when submitted on PHP end, the reason is a general user will enter incorrect data (handled by the JS) no stress on the server a cracker will remove the javascript and attempt to submit invalid data.. the PHP side deals with this and logs the attempts.. Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328295 Share on other sites More sharing options...
dbo Posted August 19, 2007 Share Posted August 19, 2007 Yup, exactly same thing I do with JS. So I agree with you Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328304 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 Well, Here's a tip; You will need javascript somewhere along the line, I suggest you learn it. W3Schools has good tutorials to get you started. Yea I know quite a bit but I am always using w3schools for a reference, I've had to go there for something with HTML once Can't remember what it was now but it was quite late in the day so i forgot how to do it lol Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328314 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 I refer to myself as the JavaTwat.. as i always get in a mess but if it has to be done, it should be done correctly **thinks about some old code.... oh my what a mess they where** Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328318 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 Well I have done some stupid bits of code before Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328326 Share on other sites More sharing options...
dbo Posted August 19, 2007 Share Posted August 19, 2007 Haven't we all. Although writing bad code or a lot of code is usually what makes us want to come up with better ways to do it. Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328333 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 Practice makes perfect, and you always learn from your mistakes. I have got these funny ones on a t-shirt Trying is the first step to failure ok I can ony remember one Quote Link to comment https://forums.phpfreaks.com/topic/65703-php-drop-down-to-redirect-url-on-the-same-page/#findComment-328335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.