Sir
Sir

Reputation: 8280

Unexpected identifier for function call

I have a simple onclick feature which calls a function but im getting an unexpected identifier but i don't see where the mistake is, it doesn't actually give me the error until i click the link which is confusing.

This is the script:

function discard_item(id,name){
 alert('test');
 return false;
} 

function load(){
   name = 'test';
   id = 1;
   output = [];

   output.push('[<a href="#" onclick="return discard_item("'+id+'","'+name+'")">Discard</a>]');

   document.getElementById('main').innerHTML = (output.join(''));

}

load();

When i click the link to call discard_item i get : Unexpected token }

Can't seem to see a mistake in my script though ? http://jsfiddle.net/Lu2HK/6/

Hope you can help!

Upvotes: 1

Views: 1962

Answers (1)

qwertymk
qwertymk

Reputation: 35266

Try this:

Change the " to escaped 's:

output.push('[<a href="#" onclick="return discard_item(\''+id+'\',\''+name+'\')">Discard</a>]');

Upvotes: 3

Related Questions