0

I have the following script located at the top of my web page to open a popup window based on the URL parameter I pass it...

<Script Language="JavaScript">
function showDetails(source) {
    window.open(source,"","scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no");
}
</Script>

And I have the following PHP code that calls the function to open the window and passes the url...

$QueryResult = @$this->DBConnect->query($SQLString);

            if ($QueryResult !== FALSE) {
                if ($QueryResult->num_rows > 0) {       
                    while (($Row = $QueryResult->fetch_assoc())
                                    !== NULL) {
                        echo "<br /><a href='javascript:showDetails(http://server/~user/PHP/EventDetails.php?PHPSESSID=".session_id()."&EventID=".$Row['EventID'].")'>".
                                htmlentities($Row['Title'])."</a>";
                    }
                }
                echo "</td>";

                if ((($FirstDOW + $i) % 7) == 0) {
                    echo "</tr>";
                }
            }

When I hover over the link on the web page the URL passed to the function looks fine, and I see something like this at the bottom of the browser, however, when I click the link it does nothing...

javascript:showDetails(http://server/~user/PHP/EventDetails.php?PHPSESSID=Hij3234Abdc732hlae&EventID=2)
5
  • 2
    Are you aware that your url must be a string, and string need to be quoted in javascript? Commented Oct 20, 2013 at 20:34
  • You need quotes around the url. javascript has no idea what http://... is, but does know that 'http://...' (note the ' quotes) is a string... Commented Oct 20, 2013 at 20:35
  • Language attribute on script element (and that in itself spelled capitalized), still using href="javascript:" instead of unobtrusive event handling … so just out of curiosity: Which century have thou traveled from to our’s, my strange friend …? Commented Oct 20, 2013 at 20:36
  • @CBroe, I don't think you need to span century boundaries to visit times where these techniques were quite common. ;) Commented Oct 20, 2013 at 20:39
  • @CBroe considering this is some of my first exposure to Javascript/PHP programming and I simply don't have the time to explore more efficient methods at this time, I think this will work fine. Commented Oct 20, 2013 at 21:55

2 Answers 2

3

You normally put strings in quotes, like

echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID="
    .session_id()."&EventID=".$Row['EventID']."\")'>".
                            htmlentities($Row['Title'])."</a>";
Sign up to request clarification or add additional context in comments.

Comments

2

Syntax error.

echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID=".session_id()."&EventID=".$Row['EventID']."\")'>".htmlentities($Row['Title'])."</a>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.