Jump to content

Problem linking to a file when using javascript in php


facarroll

Recommended Posts

I believe this is a PHP problem rather than a javascript one, but stand to be corrected.

 

The following code shows two echo statements, with the second one commented out. The uncommented statement inside the javascript will not work, because while it calls up the check.php file it does not send the associated parameters correctly. I have left the commented echo in because it works perfectly.

What's wrong?

I know that javascript works client side, but the relevant php code has already run so the javascript should work.

<?php
// code associated with a database query precedes this

     if ("{$row['passState']}" == 0) 
{
?>
<script language="javascript" type="text/javascript" >
        <--
              var newwindow;
        function popup()
   {
        newwindow = window.open('check/check.php?quizTitle=".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="popup()" value="Check your answers"></form>	';

//echo "<A HREF=\"check/check.php?quizTitle=".urlencode($quizTitle)."\" onClick=\"return popup(this, 'thoughts', 'scrollbars=1'); window.moveTo(0,0); window.resizeTo(screen.width,screen.height-100);\">Check your answers</A>.";
    }
?>

My justification for presenting a full screen popup for students is so that they can see answers they have given in an earlier quiz. I find that if their popup is just a window over their working page, they can use the popup to just fill in their answers on a second attempt. Full screen mode will limit this.

Link to comment
Share on other sites

Where your javascript code is being printed out, you are outside of PHP tags - so "urlencode" means nothing and the periods to concatenate your string also mean nothing.

 

You need to "re-enter PHP" so functions etc. are recognised:

 

var my_javascript_url = 'check/check.php?quizTitle=<?php echo urlencode($quizTitle); ?>';

 

Link to comment
Share on other sites

I changed the code as follows as was suggested by behicthebuilder. It works well now on Chrome, Firefox and iexplore, but Safari, Netscape and Opera open the page but do not deliver any dynamic content. I'm using

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Can anyone make a suggestion?

<?php
// code associated with a database query precedes this

     if ("{$row['passState']}" == 0) 
{
?>
<script language="javascript" type="text/javascript" >
        <--
              var newwindow;
        function popup()
   {
        newwindow = window.open('check/check.php?quizTitle=".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="popup()" value="Check your answers"></form>	';

//echo "<A HREF=\"check/check.php?quizTitle=".urlencode($quizTitle)."\" onClick=\"return popup(this, 'thoughts', 'scrollbars=1'); window.moveTo(0,0); window.resizeTo(screen.width,screen.height-100);\">Check your answers</A>.";
    }
?>

Link to comment
Share on other sites

Requinix. I did this...

<?php 
   if ("{$row['passState']}" == 0) 
   { 
?>
<script language="javascript" type="text/javascript
<!--
                 var newwindow;
          function popup()
   {
    newwindow = window.open('check/check.php?quizTitle=<?php echo 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="popup()" value="Check your answers"></form>	';
   }					
?>

And now I have a lovely full-screen popup window without standard controls. I have included a script to allow the user to return to the previous page.

Despite the browser problems, I think this problem is solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.