gnawz Posted May 4, 2009 Share Posted May 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 You can probably do something like <select onchage="parentNode.target = '_blank'; parentNode.submit();"> or something like that. Quote Link to comment Share on other sites More sharing options...
gaza165 Posted May 4, 2009 Share Posted May 4, 2009 or something like <select onChange="window.open('http://www.google.com','Google','width=400,height=200')"> Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 True. But that wouldn't open it native to the browser's settings, it forces it into a new window. Meh, whatever. Quote Link to comment Share on other sites More sharing options...
gaza165 Posted May 4, 2009 Share Posted May 4, 2009 Would be better if we knew where the page is going to so we can give a better solution... Quote Link to comment Share on other sites More sharing options...
gnawz Posted May 4, 2009 Author Share Posted May 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 Something like echo '<select onclick="window.open(\''.$link.'\');">'; ? Quote Link to comment Share on other sites More sharing options...
gnawz Posted May 4, 2009 Author Share Posted May 4, 2009 Yes, sth like that. But I can't use $link, before I pass it.... U know the drop down comes after the MySQL code Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 Then create an array of the links in the fetch loop. Quote Link to comment Share on other sites More sharing options...
gnawz Posted May 4, 2009 Author Share Posted May 4, 2009 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 Quote Link to comment 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.