This question already has an answer here:
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);
}
</div>
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
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']; ?>')"