0

Hey I am creating dynamic link as below. Here I am calling a function to go to the required page. I want to pass the parameters with function.

 $.each(data, function(key, value) {
        var str = value.split(':');
        trHTML += '<tr><td><a href="#" onClick="forward('+key+','+value+');">'+str[0]+'</a></td><td class="col-xs-4">'+str[1]+'</td><td class="col-xs-4">'+key+'</td></tr>';
        });

This is creating a link like this :

<a onclick="forward(241,vaibhavs:3847);" href="#">vaibhavs</a>

I know there is some problem with these parameters. They are going as variable names rather than values. The error as shown by Firebug is :

**SyntaxError: missing ) after argument list

     forward(241,vaibhavs:3847);**

So please guys suggest me the correct way to pass the parameters here.

Vaibhav Sah
  • 142
  • 1
  • 10

1 Answers1

2

Try providing quotes,

<a onclick="forward('241','vaibhavs:3847');" href="#">vaibhavs</a>
jqheart
  • 767
  • 1
  • 5
  • 15
  • If you have not seen above, i am sending the values dynamically. By the way, i got the solution by passing it in escape sequences. – Vaibhav Sah Sep 22 '15 at 15:19