Private Label and Cobranded VoIP Solutions
BrainCast internet & phone based message/memo recording & reminder organization system
Internet Phone Service and Broadband Phone Service by ViaTalk

Go Back   VoIP Forums, Internet Phone Service Forums, & Web Hosting Forums > CoderForums - Programming Discussion > General Programming Issues > Programming Languages & Technologies > PHP

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-27-2002, 06:02 PM
gamoses gamoses is offline
Registered User
 
Join Date: Nov 2001
Location: DFW
Posts: 3
Send a message via ICQ to gamoses
Warning! mySQL inside Javascript problem

I have a mySQL table with row titles and row descriptions. the idea is to have a list of titles with links to a javascript pop up box with full descriptions and other information. however, when the row description has certain html code (hyperlinks), it won't show the *title* correctly. naturally, the javascript doesn't work either. any ideas? here's the relevant code:

~ ~ ~ ~ ~

function PrintJavaScript() {
print "<!-- this java script takes the variables from an event shown below and opens a new window with the full information -->";
print "<script language=\"JavaScript\">\n";
print "<!--\n";
print "function desc_window(date,title,desc,time) {\n";
print " descWindow = window.open(\"\",\"EventDescription\",\"width=300,height=300,top=100,left=200,resizable=1,scrollbars =1,status=1\")\n";
print " descWindow.focus()\n";
print " descWindow.document.write('<HTML><HEAD><TITLE>'+title+'</TITLE></HEAD><BODY>')\n";
print " descWindow.document.write(\"<FONT face=arial size=2><B><big>\"+date+\"</big></B> <hr><b>\"+title+\"</b><br>\"+time+\"<br>\"+desc+\"<hr></BODY></HTML>\")\n";
print " autoClose = setTimeout(\"descWindow.close()\",30000)\n";
print "}\n";
print "-->\n";
print "</script>\n";
}


...


if ($desc) {
// pop up to description
$format_date = date ("l, F j, Y", mktime (0,0,0,$get_month,$get_day,$get_year));
$format_time = date ("g:i A", strtotime($this_time));
$format_title = addslashes($title);
$format_desc = addslashes($desc);
print "<a href=\"javascript:desc_window('$format_date','$format_title','$format_desc','$format_time')\">";
print stripslashes($title);
print "</a>";
}

~ ~ ~ ~ ~
Reply With Quote
  #2  
Old 04-01-2002, 02:00 PM
fatal fatal is offline
SeXy Customer
 
Join Date: Feb 2002
Posts: 23
are you calling function PrintJavaScript() anywhere?? I dont know why you have that code inside php, you could just have it printed like regular HTML.

The reason why the javascript isnt working is b/c your never calling PrintJavascript so the javascript is never written.

If I were you, I wouldn't even have a function PrintJavaScript(), rather just the javascript itself.
Reply With Quote
  #3  
Old 04-01-2002, 08:07 PM
gamoses gamoses is offline
Registered User
 
Join Date: Nov 2001
Location: DFW
Posts: 3
Send a message via ICQ to gamoses
Quote:
Originally posted by fatal
are you calling function PrintJavaScript() anywhere?? I dont know why you have that code inside php, you could just have it printed like regular HTML.

The reason why the javascript isnt working is b/c your never calling PrintJavascript so the javascript is never written.

If I were you, I wouldn't even have a function PrintJavaScript(), rather just the javascript itself.

I do call the function at the top of the page. The PrintJavaScript is in an include file.

I guess my question has more to do with why the addslashes() isn't working. Or if that isn't it, why JavaScript is reading some of the backslashed characters.
Reply With Quote
  #4  
Old 04-02-2002, 10:05 AM
top5mov top5mov is offline
Senior Customer
 
Join Date: Jun 2001
Location: Pittsburgh
Posts: 266
outputting backslashed characters with PHP can be tricky, because PHP will try to interpret the backslashes instead of passing them along to javascript.

so PHP code like this:
$text = "He said, \"What's up?\"";
print "document.write(\"$text\")";

would print a javascript line like this:

document.write("He said, "What's up?"");

which will clearly cause a syntax error. so in the string that the javascript is going to print, you have to "backslash your backslash". like so:

$text = "He said, \\\"What's up?\\\"";
print "document.write(\"$text\")";

that should produce the output:

document.write("He said, \"What's up?\"");

i'd recommend using regular expressions to replace the \" sequences with \\\"
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump