Forum Moderators: open

Message Too Old, No Replies

Javascript + PHP link

         

bsousa

10:21 am on Sep 29, 2004 (gmt 0)

10+ Year Member



hi there, i have a problem:

i have a page that has a table that lists the data from a MySQL databse and in that list, every item has a link to delete that has a function:

function apagar(val,ite) {
if(confirm('Deseja apagar o item: '+ite+'?'))
window.location='<?= $PHP_SELF?>?apagar='+val;
}

Then the delete link is written like this:

<a href="JavaScript:apagar('<?= $dados['id']?>','<?= $dados['titulo']?>');">Apagar</a>

So, when $dados['titulo'], has a quote or double quote Charater, the function doesn't work, because the javascript reads the quote character has the end of the string.

how can I solve this?

thanx

bsousa

10:53 am on Sep 29, 2004 (gmt 0)

10+ Year Member



I've tried change the link to this:

<a href="JavaScript:apagar('<?= $dados['id']?>','
<?=
$titulo = preg_replace("'&(\"¦#34);'i", "", $dados['titulo']);
echo $titulo;
?>')" class="lista_link">Apagar</a>

, but didn't work.

anyone?

dcrombie

1:06 pm on Sep 29, 2004 (gmt 0)



addslashes [php.net]?

Birdman

1:16 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



urlencode() [php.net]/urldecode() [php.net] would work as well.

StupidScript

7:49 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works with combined addslashes and htmlspecialchars, even if both a single- and a double-quote are in the string:

<a href="javascript:apagar('<?=$dados['id']?>','<?=addslashes(htmlspecialchars($dados['titulo']))?>')">Apagar</a>