Jump to content

PHP url in Javascript gives 404 not found


facarroll

Recommended Posts

I think this is a PHP topic rather than Javascript.

Can anyone tell me why this code cannot find the page (404 Not Found)

 

<?php 
if ("{$row['passState']}" == 0) 
   {
?>
<script language="javascript" type="text/javascript" >
<--
        var newwindow;
    function popupgo()
{
    newwindow = window.open('check.php?quizTitle=<?php ".urlencode($quizTitle)."; ?>','_blank', 'scrollbars=yes,top=0,left=0,width='+screen.width+',height='+screen.height);                                          
    if (window.focus) {newwindow.focus()}   
}
//-->
</script>
<?php
echo "<form><input type='button' onClick='popupgo()' value='Popup'></form>";
}					
?>

when this test code works fine? Both files are PHP.

<?php
?>
<head>
<script language="javascript" type="text/javascript" >
<--
        var newwindow;
     function popupgo()
{
     newwindow = window.open('check/check.php?quizTitle=<?php '.urlencode($quizTitle).'; ?>','_blank', 'scrollbars=yes,top=0,left=0,width='+screen.width+',height='+screen.height);
     if (window.focus) {newwindow.focus()}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onClick="popupgo()" value="Popup">
</form>
</body>
<?php
?>

You aren't actually display the $quizTitle variable, you need to echo it out.

 

Change this:

<?php ".urlencode($quizTitle)."; ?>

 

To this:

<?php echo urlencode($quizTitle); ?>

 

Also note the path change: (File 1)

'check.php?quizTitle=<?php '.urlencode($quizTitle).'; ?>'

 

Compared to: (File 2)

'check/check.php?quizTitle=<?php ".urlencode($quizTitle)."; ?>'

 

Regards, PaulRyan.

If you compare this line:

newwindow = window.open('check.php?quizTitle=<?php ".urlencode($quizTitle)."; ?>','_blank', 'scrollbars=yes,top=0,left=0,width='+screen.width+',height='+screen.height);

and this line:

newwindow = window.open('check/check.php?quizTitle=<?php '.urlencode($quizTitle).'; ?>','_blank', 'scrollbars=yes,top=0,left=0,width='+screen.width+',height='+screen.height);

Are there not several differences?

Thanks for the help both friends. The path difference is intentional, because the files are held in different tsting folders. The suggested change did not alter anything. I'll keep trying a few things.

There are still more differences than just the path. Try to copy/paste the one working, and just change the path, because I tell you there are more than just that difference.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.