PDA

View Full Version : Dynamically name dhtml window from div content



antonyf
01-15-2012, 11:09 AM
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:


<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>

jscheuer1
01-15-2012, 12:29 PM
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:


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

antonyf
01-17-2012, 02:27 PM
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