Jump to content

Recommended Posts

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!

 

 

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.

<?
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 ;)

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>

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>.

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.. ;)

 

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 ;D Can't remember what it was now but it was quite late in the day so i forgot how to do it lol

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.