JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 2nd, 2001, 10:27 PM
thedanmichael thedanmichael is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 25 thedanmichael User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem with alert: javascript is printed by php

Here's a code sample:
PHP Code:
 $sql "SELECT * FROM classes WHERE teacher = '$tid' ORDER BY period ASC";
         
$sql_result mysql_query($sql);
         while (
$row mysql_fetch_array($sql_result)) {
             
$cid $row[cid];
             
$period $row[period];
             
$grades $row[grades];
             
$description eregi_replace('"'"'",  $row[description]);
             
$class_name addslashes($row[class_name]);
             echo 
"<td><center>"; if($description) { echo "<a href=\"javascript:alert('$description');\">";} echo $class_name; if($description) { echo "</a>";}if($grades){echo " (".$grades.")";} echo "<br><input type=radio name=period_$period value=\"$cid\"></center></td>\n";
          } 


When clicked on, the link does nothing. I want it to work even if " or ' are in the description.

Reply With Quote
  #2  
Old August 3rd, 2001, 01:00 AM
szarecor szarecor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: New York
Posts: 122 szarecor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
If it's quotes that are causing your problems, you're going to have to escape them with backslashes or replace them in $description via php before concating the string you're echoing.

Reply With Quote
  #3  
Old August 3rd, 2001, 07:29 AM
JMM JMM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2001
Location: USA
Posts: 830 JMM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 17 m 56 sec
Reputation Power: 13
hi thedanmichael,

I think I see a couple of problems with your code:

Where you have the link, it looks like you've got 'java script'. It should be 'javascript' -- no space.


This part
Code:
echo "<a href=\"java script:alert('$description');\">";


I think what you're trying to do is insert the value of PHP variable 'description' in the JavaScript alert(), in which case I believe you need to concatenate the strings you're echoing, like this

Code:
echo "<a href=\"javascript:alert('", $description, "');\">";


or this

Code:
echo "<a href=\"javascript:alert('" . $description . "');\">";


When I use the PHP echo statement with HTML, I use single quotes for the echo statement because with HTML you're almost always using double quotes (of course you frequently use single quotes in JS, but...)

I hope this helps

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Problem with alert: javascript is printed by php

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap