#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    25
    Rep Power
    0

    javascript from php problem and check on eregi


    Here's a code sample:
    PHP Code:
    function listclasses($tid) {

             
    $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. Is my eregi syntax correct?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Sydney
    Posts
    41
    Rep Power
    14
    Try

    $description = eregi_replace("\"", "\'", $row[description]);

    Or use str_replace

    $description = str_replace("\"", "\'", $row[description]);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Redmond, WA
    Posts
    218
    Rep Power
    15
    Taking a quick glance, the first thing I noticed was that java script wasn't concatenated (look at the way it's written in your code). I don't know if this is intentional or not, but that may help solve problems.The way I see it, JavaScript should be responding regardless of what's returned from the server.
    Last edited by sano; August 2nd, 2001 at 11:17 PM.

IMN logo majestic logo threadwatch logo seochat tools logo