Jump to content

drop down box problem


gnawz

Recommended Posts

Hi.

I have a dynamic drop down that reads fields from the database.

 

I want a page to be opened in a new tab/window (target = _blank) when a user clicks on an item in the drop down.

 

How do I achieve that in PHP+Javascript?

 

My drop down

<select name = "sltStation">
   <option value="0">Select Station</option>
<?
$sql = "SELECT * FROM stations ORDER BY Name ASC";
		$result = dbQuery($sql);	
	if(dbNumRows($result))
	{
		while($row = dbFetchAssoc($result))
		{
			echo "<option>$row[Name]</option>";
		}
	} 
	else 
			{
			echo "<option>No Stations present</option>"; 
			}
 ?>

 

the data base consists two fields:

id, Name and Link (a hyperlink)

 

I display Name in the drop down and require that onChange, it opens the associated link in a new page

 

ie Click on name, open associated link

 

I hope I'm clear

Link to comment
Share on other sites

I 'm not sure i explained well

 

The page would be going to the Link read from the database....

 

Db has 3 fields

id, Name, Link (this is a hyperlink)

<select name = "sltStation">
   <option value="0">Select Station</option>
   <?
   $sql = "SELECT * FROM stations ORDER BY Name ASC";
         $result = dbQuery($sql);   
      if(dbNumRows($result))
      {
         while($row = dbFetchAssoc($result))
         {
            echo "<option>$row[Name]</option>";///what I dipslay for the user to select
         }
      }
      else
            {
            echo "<option>No Stations present</option>";
            }
    ?>

the dynamic drop down menu selects all fileds but in <option value, I dipslay Name.

 

I want when the user selects, a value in the dropdwon, it opens the assocaited Link

Link to comment
Share on other sites

Pardon me?

 

Isn't MySQl already fetching them in a loop? It is

 

the while row, etc thing, I'm using...

 

What i want is onClick, then the page opens in a new tab with the selected link.

 

My problem is how to achieve that with PHP/HTML and JS

Link to comment
Share on other sites

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.