0

I have this code:

while($row=mysql_fetch_array($query)){
  echo '<a onclick="return myFunction('.$row['value']'.')"></a>';
}

I need to use that dynamic parameter in a function like this:

function myFunction(my_value){
 alert('This is my value' + my_value);
 return true;
}

But the function is not called because of that parameter.Does anyone why?

Petru Lebada
  • 2,167
  • 8
  • 38
  • 59

1 Answers1

1

You have a syntax error, it should be this:

echo '<a onclick="return myFunction('.$row['value'].')"></a>';

Also if your value is a string value you need to use quotes:

echo '<a onclick="return myFunction(\''.addslashes($row['value']).'\')"></a>';

Bart Haalstra
  • 1,062
  • 6
  • 11