Page 1 of 2

Help with windows.open in php!

Posted: Sat Jun 03, 2006 11:34 am
by Trash2000
Hi and thank you all for a great forum!

I need a little bit of help with a peace of code. I have a drop-down box with gametitles, and want to open a infopage when I select a title. The code contain errors, but I cant find anyone.

Code: Select all

$sql = $db->sql_query("SELECT sid, title FROM ".$prefix."_produkter ORDER BY title");
echo "</em></i><b>Artikkel om produkt?</b>";
echo '<br><form id="catForm">';
echo "<SELECT style='WIDTH: 313px' name='assotop' width='80%'>";
echo "<option value='0'> Hent spill fra databasen </option>";
//echo "<option value=\"$sid\">$title [$sid]</option>";
while(list($sid, $title) = $db->sql_fetchrow($sql)) {
echo "<option value='$sid'>$title [$sid]</option>\n";
}
echo "</select> <button name=click OnClick=\"window.open('produkt.php?spill='+document.getElementById('catForm').assotop.value)\">Produktside!</button></font></form>";
Someone that can help me?

...And sorry for my bad English...

Posted: Sat Jun 03, 2006 11:56 am
by bdlang
What does the script output now? Do you see a blank screen or can you view the HTML output? What does 'view page source' from the browser show?

Does it show the SELECT element but not the values from the database?

Does the script fail with an error message?

Do you have any error handling built into the class that instantiates your $db object?

It would appear as though the code is meant to send the user to the script 'produkt.php', with a GET string spill and the value in the `sid` column, is this correct? Is the receiving script setup to handle the incoming GET string?

Posted: Sat Jun 03, 2006 12:05 pm
by Trash2000
The page functions like before, but the pop-up does not function. I get the drop-down, but when I click on the "open"-button does nothing happens.

$db is a part of mye CPG, and the script with the drop-down func great. Its just the script to get av pop-up page that not function.

produkt = product
spill = game
sid = unique id for each line in the db table.

The drop-down box is a part of a newsscript, and I want this script to open the games info page for the author, to get information about the game quick. When I click on the button I want to go to http://www.gamersmix.no/produkt.php?spill=$sid ($sid = uniqe ID for game).

Posted: Sat Jun 03, 2006 12:26 pm
by bdlang
Ok, well let's take a look at just the window.open code (although this is JS, not PHP). When I build a script like this, I like to take each element and output on it's own line, so it's easier to spot problems, and easier to edit code. So here's my rendition of your code, with a potential JS fix:

Code: Select all

echo '</select>';
echo "<button name='click' OnClick=\"window.open('produkt.php?spill='+document.catForm.assotop.value);\">Produktside!</button>";
echo '</font>';
echo '</form>';
Changed the string passed to the URL to simply the value of document.catForm.assotop, I see no reason to utilize getElementById here. Also used a semicolon at the end of window.open to end the statement.

See if those small fixes helped.

Posted: Sat Jun 03, 2006 2:00 pm
by Trash2000
No, still not function.

Error from IE: "document.catForm.assotop is null or it ist an object"

Posted: Sat Jun 03, 2006 2:19 pm
by ok
Like bdlang said, this is JS and not PHP!!! but....

When you check what is the selected value in a <select>, you need to use "options.selectedIndex":

Code: Select all

<button name='click' OnClick=\"window.open('produkt.php?spill='+document.catForm.assotop.options.selectedIndex);\">Produktside!</button>

Posted: Sat Jun 03, 2006 4:35 pm
by Trash2000
Nope, still error from IE: "document.catForm.assotop is null or it ist an object".

Thanks for all help, but it seems that the system dont like the code =(

Posted: Sat Jun 03, 2006 4:51 pm
by ok
I tested your first code (in the original post) and it works! Check it again (i tested it with IE and FF)

Posted: Sat Jun 03, 2006 5:11 pm
by Trash2000
Did you test with databasequery, or just "offline". I have test the original without query for db, and it function then. Its when I want to fetch the list for my DB i get problems.

Posted: Sat Jun 03, 2006 5:13 pm
by ok
Post the output of your script (HTML source)!

Posted: Sat Jun 03, 2006 5:21 pm
by Trash2000
1) Copied the script and dropped the DB query. It works.

Source:

<?php
echo '<form id="catForm">';
echo '<SELECT style="WIDTH: 313px" name=assotop width="80%">';
echo "<OPTION value=0 selected>Hent spill fra databasen</OPTION><OPTION value=310>187 Ride or Die [310]</OPTION> <OPTION value=628>2006 FIFA World Cup [628]</OPTION> <OPTION value=201>24: The Game [201]</OPTION> <OPTION value=226>25 to Life [226]</OPTION> <OPTION value=580>50 Cent Bulletproof [580]</OPTION> <OPTION value=405>7 sins [405]</OPTION> <OPTION value=241>Ace Combat 5: Squadron Leader [241]</OPTION> <OPTION value=649>Ace Combat X: Skies of Deception [649]</OPTION> <OPTION value=679>Ace Combat Zero: The Belkan War [679]</OPTION> <OPTION value=145>Act of War: Direct Action [145]</OPTION> <OPTION value=60>Advent Rising [60]</OPTION> <OPTION value=256>Age of Conan: Hyborian Adventures [256]</OPTION> <OPTION value=162>Age of Empires III: Age of Discovery [162]</OPTION> <OPTION value=732>Age of Empires: The Age of Kings [732]</OPTION> <OPTION value=450>Age of Pirates: Captain Blood [450]</OPTION> <OPTION value=448>Alan Wake [448]</OPTION> <OPTION value=733>Alex Rider Stormbreaker [733]</OPTION> <OPTION value=61>Alexander the Great [61]</OPTION> <OPTION value=491>All Points Bulletin [491]</OPTION>";
echo "</select> <button name=click OnClick=\"window.open('produkt.php?spill='+document.getElementById('catForm').assotop.value)\">Produktside!</button></font></form>";
?>

Is it the db connection that is wrong?

2) Scriptsource
<form id="catForm"><SELECT style='WIDTH: 313px' name='assotop' width='80%'><option value='0'> Hent spill fra databasen </option><option value='310'>187 Ride or Die [310]</option>
<option value='628'>2006 FIFA World Cup [628]</option>
<option value='201'>24: The Game [201]</option>
<option value='226'>25 to Life [226]</option>
<option value='580'>50 Cent Bulletproof [580]</option>
</select><button name='click' OnClick="window.open('produkt.php?spill='+document.catForm.assotop.options.selectedIndex);">Produktside!</button></font></form>

Posted: Sat Jun 03, 2006 5:29 pm
by ok
"document.getElementById('catForm').assotop.value" works fine... remember to use <html>, <head> and <body> tags, sometimes this makes the problem!!!

Posted: Sat Jun 03, 2006 5:35 pm
by Trash2000
I use them, but I use a CMS and I only included a part of my code. Thanks for all help :D , but I give up... I does not work with db :oops:

Posted: Sat Jun 03, 2006 6:20 pm
by n00b Saibot
Trash2000, first of all edit your posts and wrap [ syntax="php"][/syntax] & [ syntax="html"][/syntax] tags around your php code & html output respectively and secondly swearing is seriously discouraged as these are public fourms. People from all age groups visit these forums.

As for your question, can you point to a live one somewhere online?

Posted: Sun Jun 04, 2006 4:51 am
by bokehman
bdlang wrote:I see no reason to utilize getElementById here.
Why revert to the legacy DOM. Don't you know it doesn't work under certain mime types? application/xhtml+xml for example!