I already tried all the methods i saw here in Stackoverflow but im getting errors.
Im trying to pass a php variable value to a javascript function, im trying to do both methods:
echo '<td><a href="#" onclick="delete('.$contact['idContact'].')"> Delete </a></td>';
This method above thinks the value of the idContact is actually a variable, so he is trying to get the value of the variable "105" (the value of idContact)
echo '<td><a href="#" onclick="delete("'.$contact['idContact'].'")"> Delete </a></td>';
This method gives me
Uncaught SyntaxError: Unexpected token }
What is the correct way to do it? Thanks in advance.
Here is a simple code to show my problem:
<html>
<head>
<script>
function eliminate(test)
{
alert(test);
}
</script>
</head>
<?
$test = "name";
echo '<a href="#" onclick="eliminate('.$test.')"> Delete </a>';
?>
</html>
onclick=delete()i dont get any error so the error is in this line.