This topic is locked

Trying to open new window

6/19/2009 4:40:42 AM
PHPRunner General questions
S
swanside author

I have this code.

$id = @$_REQUEST["editid1"];

$str = "<select onchange=\"java script: window.open=this.options[this.selectedIndex].value;\">";

$str.="<option value=\"job_edit.php?editid1=".$id."\">Please select</option>";

$str.="<option value=\"labour_list.php?mastertable=job&masterkey1=".$id."\">Labour</option>";

$str.="<option value=\"material_list.php?mastertable=job&masterkey1=".$id."\">Materials</option>";

$str.="<option value=\"Full_Invoice_view.php?editid1=".$_REQUEST["editid1"]."\">Full Invoice</option>";

$str.="<option value=\"Basic_Invoice_view.php?editid1=".$_REQUEST["editid1"]."\">Basic Invoice</option>";

$str.="<option value=\"DTD_list.php?mastertable=job&masterkey1=".$id."\">DTD</option>";

$str.="<option value=\"KBC_list.php?mastertable=job&masterkey1=".$id."\">KBC</option>";

$str.="</select>";

echo $str;


I have tried changing it to this

<script type="text/javascript">

function open_win()

{

$id = @$_REQUEST["editid1"];

$str = "<select onchange=\"java script: window.open=this.options[this.selectedIndex].value;\">";

$str.="<option value=\"http://localhost/data/job_edit.php?editid1=".$id."\">Please select</option>";

$str.="<option value=\"http://localhost/data/labour_list.php?mastertable=job&masterkey1=".$id."\">Labour</option>";

$str.="<option value=\"http://localhost/data/material_list.php?mastertable=job&masterkey1=".$id."\">Materials</option>";

$str.="<option value=\"http://localhost/data/Full_Invoice_view.php?editid1=".$_REQUEST["editid1"]."\">Full Invoice</option>";

$str.="<option value=\"http://localhost/data/Basic_Invoice_view.php?editid1=".$_REQUEST["editid1"]."\">Basic Invoice</option>";

$str.="<option value=\"http://localhost/data/DTD_list.php?mastertable=job&masterkey1=".$id."\">DTD</option>";

$str.="<option value=\"http://localhost/data/KBC_list.php?mastertable=job&masterkey1=".$id."\">KBC</option>";

$str.="</select>";

echo $str;

}

</script>


But I can not any working.
The idea is it opens a new window to the selected link.
Anybody any ideas please?

Thanks

Paul

J
Jane 6/19/2009

Hi,
please check correct syntaxt here:

http://www.w3schools.com/HTMLDOM/met_win_open.asp
I suppose you need to edit this line:

$str = "<select onchange=\"java script: window.open(this.options[this.selectedIndex].value);\">";

S
swanside author 6/20/2009

Hi,

please check correct syntaxt here:

http://www.w3schools.com/HTMLDOM/met_win_open.asp
I suppose you need to edit this line:

$str = "<select onchange=\"java script: window.open(this.options[this.selectedIndex].value);\">";


Thanks Jane.

J
Jepsen 6/20/2009

I have seen a number of requests here where people asks how to open links in new pages from the database using costum code. So I thought I should just mention how I do it.
I never use costum code to do it. I always do it in the SQL query and display the field as html.
Here is an example. See this page:
http://www.vaabenhistoriskselskab.dk/arma-...stande_list.php
When you click on the photo, the view page opens. This is done in sql query as follows:

concat('<img src="', '../arma-dania/marker/foto/th', foto1, '

" onclick="javascipt:window.open(', "'_md_genstande_view.php?editid1=", id, "'

, '_self');", '" onmouseover="', "java script:this.style.cursor='hand';", '" onmouseout="', "java script:this.style.cursor='pointer';", '">') AS link_til_db,


Another example is this page:
http://www.vaabenhistoriskselskab.dk/links..._links_list.php
If you click on the photo the link will open in a new window. This also done in SQL query like this:

concat('<img src="', link_picture, '" width="150" onclick="java script:window.open(', "'", link, "', '_blank');", '">') AS Log


That is my preferred way of doing it. That was my 5 cent.
:-)

Morten