1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

onclick change value ?

Discussion in 'PHP' started by MyVodaFone, Jul 20, 2010.

  1. #1
    My search box seen here works fine, but it has a bug. When a movie title has an ' apostrophe, the value wont change.

    Heres my code:

    
    while($searchArray = mysql_fetch_array($search)) {
      
    echo "<div onclick=\"javascript:document.getElementById('dvd_search').value='".$searchArray["" . $dvd_field[2][2] . ""]."'\"> <img src=\"images/list.gif\" border=\"0\"> ".$searchArray["" . $dvd_field[2][2] . ""]."</div>";
    
    }
    
    PHP:
    Looking for some inspiration here ?
     
    MyVodaFone, Jul 20, 2010 IP
  2. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Escape single quotes.
    
    while($searchArray = mysql_fetch_array($search)) {
        echo "<div onclick=\"javascript:document.getElementById('dvd_search').value='".str_replace("'", "\'", $searchArray["" . $dvd_field[2][2] . ""])."'\"> <img src=\"images/list.gif\" border=\"0\"> ".$searchArray["" . $dvd_field[2][2] . ""]."</div>";
    }
    
    PHP:
     
    Deacalion, Jul 20, 2010 IP
    MyVodaFone likes this.
  3. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    By the way, I didn't use addslashes() because it would also escape double quotes ("). Which could be part of a movie title.
     
    Deacalion, Jul 20, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    That was the answer, thanks very much, however I ran into problems searching the db so I decided just to remove the apostrophe from all movie titles, thanks anyway.
     
    Last edited: Jul 21, 2010
    MyVodaFone, Jul 21, 2010 IP