Reputation: 15
I have 2 variables outside. want to display those 2 variable values inside onclick event.. Cant able to get value using my below code.. please help me to solve this issue. Have to fix this issue in 3 hours.
var myCode = "12345";
var myCount = "5"
$('.cols2.continue').html('<a href="#" onClick="test.element='myCode, myCount ';test.elemName=+myCode +;">Browse</a>');
Now, i m getting variable name in place of value.
Thanks
Upvotes: 0
Views: 117
Reputation: 62005
Consider not HTML mangling:
var myCode = function () {
/* Don't use a string for "code" here either,
then it can be used as a normal function later on. */
}
var myCount = "5"
var $a = $('<a href="#">Browse</a>')
/* Yay, normal event callback function (and closure)! */
$a.click(function () {
myCode()
alert(myCount)
})
/* In most cases it's like sufficient just to add the element;
to replace all content, use .empty().append($a) */
$('.cols2.continue').append($a)
Upvotes: 2
Reputation: 5962
your jquery would be
var myCode = "12345";
var myCount = "5"
$('.continue').html('<a href="#" onClick="test.element=''+myCode+', '+myCount+' ';test.elemName='+myCode+ ';">Browse</a>');
Upvotes: 0
Reputation: 3555
Try this:
var myCode = "12345";
var myCount = "5";
$('.cols2.continue').html('<a href="#" onClick="test.element=''+myCode+', '+myCount+''test.elemName='+myCode +';">Browse</a>');
Upvotes: 0