Page 1 of 1
problem with bubbles
Posted: Tue Nov 21, 2006 5:05 am
by danihel
hi
please anyone knows how to create javascript bubble
like this:
Code: Select all
<div id="'.$i.'">Show Comments</div>
<script type="text/javascript">
document.getElementById("'.$i.'").title="'.$record['comments'].'"
</script>
when the text in the bubble contains more than one row?
Posted: Tue Nov 21, 2006 6:00 am
by JayBird
Moved to Client Side
Posted: Tue Nov 21, 2006 6:48 am
by danihel
not sure this is a java script problem cuz i need to know how to remove in php all characters that are preventing java to pop up the comments bubble
this problem occures only when the var with comments text contains new lines
Posted: Tue Nov 21, 2006 8:35 am
by JayBird
I think you need to show more of your code then!
Posted: Tue Nov 21, 2006 9:04 am
by danihel
ok
the piece of code that is not working as i would like to, is a part of table that should show comments in a bubble done by java script
the whole table looks like this:
Code: Select all
dbConnect();
$result = mysql_query("SELECT * FROM `PSuche`");
echo "<table border=1 bgcolor='#EAEAEA' align = left>". "<tr bgcolor='#999999'><td><b>Nr.:</b></td><td><b>Termin:</b></td>" ."<td><b>Zeit:</b></td><td><b>Anrede:</b></td><td>". "<b>Vorname:</b></td><td><b>Name:</b></td><td><b>." "<nobr>Telefon Nr.:</nobr></b></td><td><b>Mobil:</b></td>". "<td><b>Email:</b></td><td><b>Stärke:</b></td><td><b>". "Bemerkungen:</b></td><td><b>Status:</b></td></tr>";
if (mysql_num_rows($result) > 0){
$i = 1;
while ($record = mysql_fetch_assoc($result)){
echo "<tr><td>".$i.".</td><td> ";
if ($record["term"] == $noDate) {
echo "Offen</td><td>Offen";
}
else {
echo "".date("d-m-Y", strtotime($record["term"]))."</td><td>".zeit($record["zeit"])."";
}
echo "</td><td>".$record["sex"]."</td><td><b>".$record["first"]. "</b></td><td><b>". $record["last"]. "</b></td><td><nobr>". $record["phone"] ."</nobr></td><td><nobr>".$record["cellphone"]. "</nobr></td><td><nobr>". $record["email"] ."</nobr></td><td>". $record["skill"]. "</td><td>";
if ($record["AutoID"] == $showComments){
echo "<A HREF='s8.php'>".stripslashes(nl2br($record["comments"]))."</A>";
}
elseif ($record["comments"]){
echo '<center><A HREF="s8.php?showComments='.$record['AutoID'].'" id="'.$i.'">Anzeige</A>
<script type="text/javascript">
document.getElementById("'.$i.'").title="'.str_replace("\n", " ", $record['comments']).'"
</script></center>';
}
else echo "";
echo "</td><td>".$record["status"]."</td>";
if ($record["pass"]){
echo "<FORM METHOD=POST ACTION='passwort.php'>
<INPUT TYPE=HIDDEN name='statusChangeID' VALUE=".$record["AutoID"]."><td>
<INPUT TYPE=SUBMIT VALUE='ändern'></td>
</FORM>";
}
else
{
echo "<FORM METHOD=POST ACTION='s8.php'>
<INPUT TYPE=HIDDEN name='statusChangeID' VALUE=".$record["AutoID"]."><td>
<INPUT TYPE=SUBMIT VALUE='ändern'></td>
</FORM>";
}
echo "</td>
</tr>";
$i++;
}
this is the part of table that doesnt work properly:
Code: Select all
elseif ($record["comments"]){
echo '<center><A HREF="s8.php?showComments='.$record['AutoID'].'" id="'.$i.'">Anzeige</A>
<script type="text/javascript">
document.getElementById("'.$i.'").title="'.str_replace("\n", " ", $record['comments']).'"
</script></center>';
}
if the people who posted comments entered more than one row in the comments input, the bubble doesnt work.
I tried to replace the "\n" character with " "-white space:
Code: Select all
str_replace("\n", " ", $record['comments'])
but it doesnt work anyway
please any ideas are welcome
feyd | edited to stop from breaking page layout.
Posted: Tue Nov 21, 2006 9:40 am
by Popcorn
Hi

,
Firstly "JavaScript", not "Java script" or "Java" , JavaScript is not related to Java.
You probably have the same problem most of us have had once (quoting wikipedia ... hilarious):
http://en.wikipedia.org/wiki/Javascript_syntax:
Unlike C, whitespace in JavaScript source can directly impact semantics. Because of a technique called "semicolon insertion", any statement that is well formed when a newline is parsed will be considered complete (as if a semicolon were inserted just prior to the newline).
Escape *everything* that will conflict with JavaScript variable assignment. I also replace \r and \r\n to be safe. As JavaScript strings can be delimited by ' or " you should also escape those.
Maybe something like:
Code: Select all
...document.getElementById("'.$i.'").title="'.jsescape($record['comments']) ...
where jsescape() is your fn to replace newlines and quotes.
Lastly, forgive me if I am mistaken but if you are starting out you should read up on (X)HTML. You are mixing case (HTML doesn't care but XHTML does) and not properly or consistently enclosing element attribute values. Get in the habit now, so you don't need to make as many changes for standards compliance in the future.
Good luck.
Posted: Tue Nov 21, 2006 1:02 pm
by danihel
man, i was struggling with it for days, none could help me on other forum,
and now it finaly works, you just saved my life
my deepest thanks to you mate
and thanks for the other advise too
Posted: Tue Nov 21, 2006 7:35 pm
by Popcorn
No prob. Glad I could be of some help
