I want to pass a string that contains few words to jQuery when click on the link.
It works with parameters that are integers or single words, but when the parameter is a string that consists of few words, the function does not execute.
Example:
$name='Steve';
$fullName='Steve Jobs';
<a href="javascript:void(0)" onclick="send(<? echo $name; ?>)">Link 1</a>
<a href="javascript:void(0)" onclick="send(<? echo $fullName; ?>)">Link 2</a>
Javascript code:
function send(name){
alert (name);
}
Link 1 works.
Link 2 does not work.
How to make Link 2 to work?
You need quotes around the echo’d variables since they are to be interpreted as strings, not javascript variable names: