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.

0

2 Answers 2

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('')

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

sorry but in my post i forgot write function but in my code it's written.

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.