strange popup problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

strange popup problem

Post by mcog_esteban »

hi..i'm using a javascript popup with php to show some messages..but when i pass the message to the popup something very strange happens.
if i do $msg = "message comes here"; it gives me an error(javascript error), if i do $msg ="messagecomeshere" everything works fine.
i don't know whats happening, it works well till i insert a space,nl,etc.
can some one help me?
i can post the code if it helps.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Try $msg = "message comes here"

Note! In the example that works, you do NOT have a semicolon. And above there is no semicolon...I doubt that works, but try it anyway.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

the problem it's not that.
if i took the semicolon, php gives a parse error.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Let's see your code.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

-- friend.php --
<?php

if (!$city)
{
$cidade = 'Viana';
}
else
{
$cidade = $city;
}

$friends[] = "Nuno \"nick\" Faria";
$friends[] = "Susana \"nick\" Pereira";
$friends[] = "Miguel \"nick\" Pinto";
$friends[] = "Alberto \"nick\" Simões";
$friends[] = "José \"nick\" Alves";
$friends[] = "José \"nick\" Moura";
$friends[] = "Paulo \"nick\" Cabral";

echo "<html>\n";
echo "<head>\n";
echo "<LINK href=\"chrome.css\" type=text/css rel=stylesheet>\n";
echo "</head>\n";
echo "<body>\n";
echo "<DIV ID=\"dek\" class=\"dek\"></DIV>";
echo "<script language=JavaScript type=text/javascript src=\"dek.js\"></script>\n";
echo "<p align=\"center\"><font face=\"verdana\" size=\"4\">\n";
echo "<a href=\"$php_self?pagina=friends&city=Braga\"><b>Braga</b></a>\n";
echo " e <a href=\"$php_self?pagina=friends&city=Viana\"><b>Viana</b></a></font>\n";
//echo "<p align=center>these are with any doubt my best friends i meet over the years in Braga\n";
echo "<br>\n";
echo "my friends in $cidade<br>\n";

sort($friends);
//$a = count($friends);
//$b = $friend[0];
//$nome = $friends[0];
$imagem = 'images/friend.jpg';
//echo "$a<br>\n";
echo "<br>\n";
echo "<div align=left><br>\n";
echo "<table width=\"50%\" cellspacing=\"2\">\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[0]</a></td></tr>\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[1]</a></td></tr>\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[2]</a></td></tr>\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[3]</a></td></tr>\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[4]</a></td></tr>\n";
echo "<tr><td bgcolor=\"#aaaa00\" width=\"50%\" height=\"5%\"><a href=\"#\" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[5]</a></td></tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>

-- chrome.css --

BODY {
FONT-SIZE: 20px; MARGIN: 10px; COLOR: #ffffff; FONT-FAMILY: MS Sans Serif, Arial, Helvetica; BACKGROUND-COLOR: #a4491d; SCROLLBAR-FACE-COLOR: #e1d8ce; SCROLLBAR-HIGHLIGHT-COLOR: #e1d8ce; SCROLLBAR-SHADOW-COLOR: #e1d8ce; SCROLLBAR-3DLIGHT-COLOR: #e1d8ce; SCROLLBAR-ARROW-COLOR: #d95d18; SCROLLBAR-TRACK-COLOR: #a4491d; SCROLLBAR-DARKSHADOW-COLOR: #e1d8ce
}
TH {
FONT-SIZE: 14px; COLOR: #ffffff; FONT-FAMILY: MS Sans Serif, Arial, Helvetica; BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid; BACKGROUND-COLOR: #000000
}

TD {
FONT-SIZE: 14px; COLOR: #ffffff; FONT-FAMILY: MS Sans Serif, Arial, Helvetica; BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid; BACKGROUND-COLOR: #000000
}

TD.test{
FONT-SIZE: 12px;
FONT-FAMILY: MS Sans Serif, Arial, Helvetica;
border: 1px solid #eeeedd;
color: black;
background: #eeeedd;
padding: 2px;
}

TD.test2{
FONT-SIZE: 12px;
FONT-FAMILY: MS Sans Serif, Arial, Helvetica;
border: 1px solid white;
color: white;
background: black;
padding: 2px;
}

A:link {
COLOR: #ffffff; TEXT-DECORATION: none
}
A:visited {
COLOR: #ffffff;
TEXT-DECORATION: none
}
A:active {
COLOR: #aa0000; TEXT-DECORATION: none
}
A:hover {
BACKGROUND-COLOR: #ffffff;
COLOR: #000000
}

DIV {
FONT-SIZE: 14px; COLOR: #ffffff; FONT-FAMILY: MS Sans Serif, Arial, Helvetica
}

DIV.dek{
POSITION : absolute;
VISIBILITY : hidden;
Z-INDEX : 200;
}

input {
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #5a6ba1; border: #5a6ba1; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-left-width: 1px; border-bottom-width: 1px; background-color: #ffffff
}

textarea {
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #5a6ba1; border: #5a6ba1; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-left-width: 1px; border-bottom-width: 1px; background-color: #ffffff
}

-- dek.js --
//Pop up information box II (Mike McGrath (mike_mcgrath@lineone.net, http://website.lineone.net/~mike_mcgrath))
//Permission granted to Dynamicdrive.com to include script in archive
//For this and 100's more DHTML scripts, visit http://dynamicdrive.com

Xoffset=505; // modify these values to ...
Yoffset=219; // change the popup position.

var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all

if (ns4)
skn=document.dek
else if (ns6)
skn=document.getElementById("dek").style
else if (ie4)
skn=document.all.dek.style
if(ns4)document.captureEvents(Event.MOUSEMOVE);
else{
skn.visibility="visible"
skn.display="none"
}
document.onmousemove=get_mouse;

function popup(header,msg,imagem,color){
var content="<TABLE WIDTH=290 height=200 CELLPADDING=0 cellspacing=1 bgcolor="+color+" "+
"><th>"+header+"</tr><tr><TD width=290 height=100 ALIGN=center><FONT COLOR=white SIZE=2>"+msg+"</FONT></TD></tr>"+
"<tr><td align=center width=290 height=100 align=center><img src="+imagem+"></td></tr></TABLE>";
yyy=Yoffset;
if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
if(ns6){document.getElementById("dek").innerHTML=content;skn.display=''}
if(ie4){document.all("dek").innerHTML=content;skn.display=''}
}

function get_mouse(e){
//var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
skn.left=Xoffset;
//var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
skn.top=yyy;
}

function kill(){
yyy=-1000;
if(ns4){skn.visibility="hidden";}
else if (ns6||ie4)
skn.display="none"
}


try play around in friends.php with the popup params(i can´t pass more than 1 word).
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i doubt it's the css file, and i think this will help peopole look at the php file.. as would some comments. not for the future and if you wanna repost with comments: look at the code and php tags that you have in the posting page.
mcog_esteban wrote:-- friend.php --

Code: Select all

<?php	
	
if (!$city)
{
	$cidade = 'Viana';
}
else
{
	$cidade = $city;
}
			
$friends[] = "Nuno "nick" Faria";
$friends[] = "Susana "nick" Pereira";
$friends[] = "Miguel "nick" Pinto"; 
$friends[] = "Alberto "nick" Simões";
$friends[] = "José "nick" Alves";
$friends[] = "José "nick" Moura";
$friends[] = "Paulo "nick" Cabral";

echo "<html>\n";
echo "<head>\n";
echo "<LINK href="chrome.css" type=text/css rel=stylesheet>\n";
echo "</head>\n";
echo "<body>\n";
echo "<DIV ID="dek" class="dek"></DIV>";
echo "<script language=JavaScript type=text/javascript src="dek.js"></script>\n";
echo "<p align="center"><font face="verdana" size="4">\n";
echo "<a href="$php_self?pagina=friends&city=Braga"><b>Braga</b></a>\n";
echo " e <a href="$php_self?pagina=friends&city=Viana"><b>Viana</b></a></font>\n"; 
//echo "<p align=center>these are with any doubt my best friends i meet over the years in Braga\n";
echo "<br>\n";
echo "my friends in $cidade<br>\n";

sort($friends);
//$a = count($friends);
//$b = $friend[0];
//$nome = $friends[0];
$imagem = 'images/friend.jpg';
//echo "$a<br>\n";
echo "<br>\n";
echo "<div align=left><br>\n";
echo "<table width="50%" cellspacing="2">\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[0]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[1]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[2]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[3]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[4]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[5]</a></td></tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>
-- dek.js --

Code: Select all

//Pop up information box II (Mike McGrath (mike_mcgrath@lineone.net,  http://website.lineone.net/~mike_mcgrath))
//Permission granted to Dynamicdrive.com to include script in archive
//For this and 100's more DHTML scripts, visit http://dynamicdrive.com

Xoffset=505;    // modify these values to ...
Yoffset=219;    // change the popup position.

var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&amp;&amp;!document.all
var ie4=document.all

if (ns4)
skn=document.dek
else if (ns6)
skn=document.getElementById("dek").style
else if (ie4)
skn=document.all.dek.style
if(ns4)document.captureEvents(Event.MOUSEMOVE);
else&#123;
skn.visibility="visible"
skn.display="none"
&#125;
document.onmousemove=get_mouse;

function popup(header,msg,imagem,color)&#123;
var content="&lt;TABLE WIDTH=290 height=200 CELLPADDING=0 cellspacing=1 bgcolor="+color+" "+
"&gt;&lt;th&gt;"+header+"&lt;/tr&gt;&lt;tr&gt;&lt;TD width=290 height=100 ALIGN=center&gt;&lt;FONT COLOR=white SIZE=2&gt;"+msg+"&lt;/FONT&gt;&lt;/TD&gt;&lt;/tr&gt;"+
"&lt;tr&gt;&lt;td align=center width=290 height=100 align=center&gt;&lt;img src="+imagem+"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/TABLE&gt;";
yyy=Yoffset;
 if(ns4)&#123;skn.document.write(content);skn.document.close();skn.visibility="visible"&#125;
 if(ns6)&#123;document.getElementById("dek").innerHTML=content;skn.display=''&#125;
 if(ie4)&#123;document.all("dek").innerHTML=content;skn.display=''&#125;
&#125;

function get_mouse(e)&#123;
//var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
skn.left=Xoffset;
//var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
skn.top=yyy;
&#125;

function kill()&#123;
yyy=-1000;
if(ns4)&#123;skn.visibility="hidden";&#125;
else if (ns6||ie4)
skn.display="none"
&#125;

try play around in friends.php with the popup params(i can´t pass more than 1 word).
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ok. i suggest a few things. one: comment it for us
2: go to php.net and read about heredoc syntax. ( http://us2.php.net/manual/en/language.t ... ax.heredoc ) it may make it much more readable
to demo the point:

Code: Select all

<?php   
   
if (!$city)
{
   $cidade = 'Viana';
}
else
{
   $cidade = $city;
}
         
$friends[] = "Nuno "nick" Faria";
$friends[] = "Susana "nick" Pereira";
$friends[] = "Miguel "nick" Pinto";
$friends[] = "Alberto "nick" Simões";
$friends[] = "José "nick" Alves";
$friends[] = "José "nick" Moura";
$friends[] = "Paulo "nick" Cabral";

echo <<<END
<html>
<head>
<LINK href="chrome.css" type=text/css rel=stylesheet>
</head>
<body>
<DIV ID="dek" class="dek"></DIV>

END;

echo "<script language=JavaScript type=text/javascript src="dek.js"></script>\n";
echo "<p align="center"><font face="verdana" size="4">\n";
echo "<a href="$php_self?pagina=friends&city=Braga"><b>Braga</b></a>\n";
echo " e <a href="$php_self?pagina=friends&city=Viana"><b>Viana</b></a></font>\n";
//echo "<p align=center>these are with any doubt my best friends i meet over the years in Braga\n";
echo "<br>\n";
echo "my friends in $cidade<br>\n";

sort($friends);
//$a = count($friends);
//$b = $friend[0];
//$nome = $friends[0];
$imagem = 'images/friend.jpg';
//echo "$a<br>\n";
echo "<br>\n";
echo "<div align=left><br>\n";
echo "<table width="50%" cellspacing="2">\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[0]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[1]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[2]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[3]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[4]</a></td></tr>\n";
echo "<tr><td bgcolor="#aaaa00" width="50%" height="5%"><a href="#" onMouseOver=javascript:popup('header','msg','$imagem','#000000') onmouseout=javascript:kill()>$friends[5]</a></td></tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>
one last thing, in html and ESPECIALLY xhtml, all the things after = should be in "" not just some. also, end the javascript with ; it'll like it MUCH more.
Post Reply