Reputation: 1668
I'm generating a table through ajax function. But I need to add onclick function.Inside this function passing two parameters one is number and other is name.
Controller
$table.=' <td><input type="checkbox" value="" id="sp_'.$app_id.'" onclick="SpDetails('.$app_id.','.$app_details->app_name.');" /></td>'
echo $table;
script
function SpDetails(val,name)
{
alert(name)
}
But I didn't get the name when I alert.
Upvotes: 0
Views: 2635
Reputation: 2324
"
here id="sp_'.$app_id.'" "
."foo \" foo"
."$variable"
.so your code should be like this
$table.=" <td><input type='checkbox' value='' id='sp_$a' onclick='SpDetails($a,\"$b\");' /></td>";
echo $table;
Upvotes: 1
Reputation: 4584
your parameter has no quote so it throws error . Use \'
for making parameter as a string .
$table ='<td><input type="checkbox" value="" id="sp_'.$app_id.'" onclick="SpDetails(\''.$app_id.'\',\''.$app_details->app_name.'\');" /></td>';
That will write in html as
<input onclick="SpDetails('app_id','app_name');"> //that is just example
Your orginal is
<input onclick="SpDetails(app_id,app_name);"> //no quote so assume as variable
Upvotes: 2
Reputation: 4766
try following:
onclick="SpDetails('" .$app_id. "','" .$app_details->app_name. "');"
Upvotes: 0