0

I have one c# web application in which put one link dynamically like,

if (oObj.aData[1] == '2') {                                
    Id = oObj.aData[7];
    Name = oObj.aData[2];
    alert(Name);
    return '<a href=#  onClick="Show(' + Id + ',' + Name + ');"> Show </a>'; 
    //this is        
}

function like,

function Show(id,name)
{
  alert('calling');
}

but my function not calling.

Is any syntax error or anything else which I forgetting?

Please help.

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
Kinjal Patel
  • 83
  • 3
  • 12

2 Answers2

2

You need to pass Name in quotes(''), with in quotes to be treated as string parameter. Otherwise they will be treated as JS variable which obviously you have not defined, You must be getting error 'example string' is not defined. in browser console.

return '<a href=#  onClick="Show(' + Id + ',\'' + Name + '\');"> Show </a>';

Note: If Id is a string, also pass it in quotes('')

Satpal
  • 132,252
  • 13
  • 159
  • 168
0

This may be of some help.

Starting from Firefox 34 and Chrome 41 you will be able to use an ECMAScript 6 feature called Template Strings and use this syntax:

String text ${expression} Example:

var a = 5;
var b = 10;
console.log(`Fifteen is ${a + b}.`);
// "Fifteen is 15.

source: JavaScript Variable inside string without concatenation - like PHP

Community
  • 1
  • 1
Nicholas Mordecai
  • 859
  • 2
  • 12
  • 33