Results 1 to 3 of 3

Thread: Dynamically name dhtml window from div content

  1. #1
    Join Date
    Aug 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Dynamically name dhtml window from div content

    1) Script Title: Dhtml window script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

    3) Describe problem: Hi. I'm trying to dynamically name the dhtml window from the content of a div.. All this is easy enough. I just don't know how to output the javascript into the title of the dhtmlwindow.open script.

    Notes:
    - the script is echoed.
    - the script is on a .php page

    Here is my code:
    PHP Code:
    <script type="text/javascript">
    var 
    windowtitle document.getElementById(\''.$username.'id\').innerHTML; // this variable works

    var online = "<a href=\"javascript:void(0);\" onclick=\"parent.dhtmlwindow.open(\''
    .$username.'box\', \'div\', \''.$profemail2.'\', document.write(windowtitle), \'width=224px,height=227px,left=200px,top=150px,resize=0,scrolling=0,center=1\'); return false\"><font style=\"padding-left:0px; width:100%; background-color:transparent;color:#000000; font-size:11px; text-decoration:none; text-align:left\">CHAT ONLINE</font></a>";
    </script> 

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    That's neither valid PHP nor valid javascript code. If it's PHP, where are the echo directives you mentioned?

    It looks to me to be more like javascript. If so, here's what you might do:

    Code:
    <script type="text/javascript"> 
    var windowtitle = document.getElementById('<?php echo $username .'id'; ?>').innerHTML; // this variable works 
    
    var online = "<a href=\"javascript:void(0);\" onclick=\"parent.dhtmlwindow.open('<?php echo $username . 'box'; ?>', 'div', '<?php echo $profemail2; ?>', '" + windowtitle + "', width=224px,height=227px,left=200px,top=150px,resize=0,scrolling=0,center=1); return false"><font style=\"padding-left:0px; width:100%; background-color:transparent;color:#000000; font-size:11px; text-decoration:none; text-align:left\">CHAT ONLINE</font></a>"; 
    </script>
    Whatever you do, if there's a problem, load up the page in the browser. Use the browser's 'view source' to see how the PHP tokens are being resolved. You should then be able to edit the code so that it produces the desired result in the source view, which of course should conform to that required by the javascript. This is no different than any javascript which is written in whole or in part by PHP.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi thanks John. I left adding the echo out sorry for that confusion. The fix you gave me worked as always.

    I still used the '.$variable.' instead of the <?php echo $variable ?> as the entire html was echoed already.

    Thanks again

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •