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.

1
  • Hey Guys, I have solved it by using escape sequences. <a href="#" onClick="forward(\''+key+'\',\''+value+'\');"> Commented Sep 22, 2015 at 15:20

1 Answer 1

2

Try providing quotes,

<a onclick="forward('241','vaibhavs:3847');" href="#">vaibhavs</a>
Sign up to request clarification or add additional context in comments.

1 Comment

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. <a href="#" onClick="forward(\''+key+'\',\''+value+'\');">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.