1

On my page, the following function has been created:

<SCRIPT language="javascript" type="text/javascript">
    function popModData( modName )
    {
        var url = "./modList.php?mod=" + modName;
        newWindow = window.open( url, modName, 'width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
        if( window.focus ) { newWindow.focus() }
        return false;
    }
</SCRIPT>

And, the page itself is modList.php which loads data of different game-mods from SQL table. I want each of the game-mod name clickable, so that a pop-up opens. I am using this in the php page generation:

while( $modTable = mysql_fetch_array( $getMod ) )
{
    $colour = ( $i % 2 )? "#99EECC" : "CCDDFF";
    echo "\t\t\t<tr bgcolor='$colour'>";
    echo "\n\t\t\t\t<td>" . $i++ . ".</td>";
    echo "\n\t\t\t\t<td onclick='return popModData($modTable[Name]);'>$modTable[Name]</td>";
    echo "\n\t\t\t\t<td>$modTable[From]</td>\n\t\t\t</tr>";
}

Upto this, no trouble is faced. Now, the trouble is pop-up window opens for the first entry in the table, but not for any of the other 516 values.

I thought of having another file to process the mod name( for eg. modData.php ) but, the problem is still there.

Please help. If anything is missing there, please mention, and I will try to put it up too!

3
  • Can you post the generated HTML? Commented Feb 5, 2012 at 8:55
  • ^ this. And: where do you initialize the $i counter? How's the sql query? Commented Feb 5, 2012 at 8:58
  • @damien $i is initiated just above while loop as $offset+1 Commented Feb 5, 2012 at 9:19

1 Answer 1

2

Surround the names with " " as you need javascript to parse them as strings.

Like this:

while( $modTable = mysql_fetch_array( $getMod ) )
{
    $colour = ( $i % 2 )? "#99EECC" : "CCDDFF";
    echo "\t\t\t<tr bgcolor='$colour'>";
    echo "\n\t\t\t\t<td>" . $i++ . ".</td>";
    echo "\n\t\t\t\t<td onclick='return popModData(\"$modTable[Name]\");'>$modTable[Name]</td>";
    echo "\n\t\t\t\t<td>$modTable[From]</td>\n\t\t\t</tr>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Dunno why it worked now. I tried putting it like return popModData('$modTable[Name]'); and return popModData(\'$modTable[Name]\'); too.
You are already inside an onclick='...' dont use ' inside ' as it makes no difference in js if you use ' or ", so you can always use he other. Also php possibly ate the \ anyway.

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.