Hello, I am trying to get php to echo a javascript script. Here's what Im trying to do. I have 3 parts. I am using javascript to remotely call a php file like this:

<script language="JavaScript" src="check.php?id=777
</script>

This is located on just about all my html pages. And it sends the value for id and the php file checks to see if that is a registered user number.

Now what I want this php file to do after getting and going through its if statements is to echo javascript: I want a new window to pop up with specific height and width. Im sure this is the correct javascript code to so this. Since its being called remotely I leave out the <Script> tags also the variable with the dollar sign is there since php will parse it:

document.write( "<A HREF=members/index.php?$id onClick=\"window.open('members/index.php?$id', 'Member Check', 'width=400,height=500,resizable=yes,scrollbars=yes'); return false;\"> Check If Name Is in Use</A>" );

I need the false there so the current page does not change.

Now I have serious problems when I put that into a php echo statement like so. As you see I used the backlashes but still I can't get it to come up without a problem I know I need to change something but my javascript skills aren't great so I just can't figure it Out thanks in advance. Also here is how I attempt to echo it. I have tried many other variants but theres to many to post. they all haven't worked tho.

<?php

echo "document.write( "<A HREF=members/index.php?$id onClick=\"window.open('members/index.php?$id', 'Member Check', 'width=400,height=500,resizable=yes,scrollbars=yes'); return false;\"> Check If Name Is in Use</A>" );";

?>

Thanks for all the help.

Kyle

    <?php 
    echo 'document.write( "<A HREF=members/index.php?' . $id . 'onClick=\"window.open(\"members/index.php?' . $id . '\", \"Member Check\", \"width=400,height=500,resizable=yes,scrollbars=yes\"); return false;\"> Check If Name Is in Use</A>" );'; 
    
    ?>
    

    I'm not big on JS but I believe it still escapes "'s with a .... try that....

      Thank You For your help. But I still get two unterminated string constant javascript errors. Does anyone have alternate ways of opening a new window with specific size?

        echo "<a href=\"#\" onclick=\"window.open('members/index.php?" . $id . "','Member Check','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=500,left=0,top=0'); return false;\">click here</a>";
        

          u esacped it, good
          but that escaping was for javascript.

          u have to escape it again for php.
          use what seby gave above, that should work

            Originally posted by seby

            echo "<a href=\"#\" onclick=\"window.open('members/index.php?" . $id . "','Member Check','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=500,left=0,top=0'); return false;\">click here</a>";
            

            [/B]

            In this situation, though, it would be much simpler (because there's less hassle about which bits get quoted how often) to just go

            ?>
            <a href="#" onclick="window.open('members/index.php?<?php echo $id?>',
            'Member Check', 'scrollbars=yes,width=600,height=500,left=0,top=0'); return false;">click here</a>
            <?php
            

            (And note that once you start saying "yes" to window properties, any properties you don't mention are automatically taken to be "no". Just saves a bit of code.)

              I figured it out with the help of you guys and some studying of scripts I found. The code proposed may have worked but for some reason having php echo it conflicted with the script and really messed stuff up. And on the other hand the ones that did work did not work when I tried to have the javascript SRC include it . The Solution was to make the .php file and have just plain text. The file started with a function... no Tags!

              popupwindow()
              {
              var new = "member.php?" <?php $id; ?>
              pop window code here
              }
              var spout = "<a href='JavaScript:void(0)' OnClick='tellwindow()'>Member Check</a>" ;
              document.write( spout ) ;

              This way it loads from the src call from the javascript on your loading page. I hope this helps people who are trying to do the same thing.

                Write a Reply...