-2

Im tring to pass a string which im getting from my database to a javascript function.

In my php I have:

<input type="image" name="edit_me" id="edit_me"  value="<?php echo $row['id']; ?>" onClick="edit_chirp(<?php echo $row['id']; ?>)"/> //THIS WORKS

When I pass the id im getting it works fine but when I pass a field where it has text it doesnt work.

<input style="float:right" type="image" name="edit_me" id="edit_me"  value="<?php echo $row['id']; ?>" onClick="edit_chirp(<?php echo $row['content']; ?>)" //THIS DOESNT WORK

My javascript function is

function edit_chirp(somethig)
    {
        alert(somethig);
    }
EMAD SEYED
  • 13
  • 4

2 Answers2

1

You have been missing quotes dude. Try this

<input style="float:right" type="image" name="edit_me" id="edit_me"  value="<?php echo $row['id']; ?>" onClick="edit_chirp('<?php echo mysql_real_escape_string($row['content']); ?>')" //THIS WILL WORK
Voonic
  • 4,419
  • 3
  • 26
  • 56
0

Try to add simple quotes in the function call for the parameter. Something like this :

<input style="float:right" type="image" name="edit_me" id="edit_me"  value="<?php echo $row['id']; ?>" onClick="edit_chirp('<?php echo $row['content']; ?>')"
guikk
  • 185
  • 5