0

I have a javascript function that dynamically builds a table. I have a function that gets called once a button inside of that table is clicked.

var bankButtonRefresh = '<a href="javascript:void(0)" onClick="refreshBankDataFunction('+parentId+')" 
class="btn-sm btn-primary permissionDeny pull-right" role="button">Refresh</a>';
row +='<td style="position:relative">' + bankButtonRefresh2 + '</td>';

When I printed out the value of bankButtonRefresh2 the value is:

<a href="javascript:void(0)" onClick="refreshBankDataFunction(a34c0000000jiecccA)" 
class="btn-sm btn-primary permissionDeny pull-right" role="button">Refresh</a>

So I can see that the parentId is passing incorrectly.

I am not trying to do anything fancy, I am just trying to get the Id passed to the function but I am getting no response from the button when I click on it.

function refreshBankDataFunction(obj){ //obj is the parentId
      alert('got into the function: ' + obj);
}

Am I not passing the parentId correctly?

6
  • 2
    There is no type that matches a34c0000000jiecccA. Did you mean to wrap that in quotes? Commented May 12, 2017 at 21:53
  • I thought it would pick it up as a type- ID Commented May 12, 2017 at 21:55
  • @Olivia, Joseph means it will work if you do this: refreshBankDataFunction('a34c0000000jiecccA') Commented May 12, 2017 at 21:57
  • 1
    If you leave it without quotes, JS will think it's a variable and not an actual value Commented May 12, 2017 at 21:57
  • I see. the only issue with that is the HTML reads the parentId as a string if I do that: onchange="refreshBankDataFunction('+ ''' + parentId + ''' +')" Commented May 12, 2017 at 22:00

2 Answers 2

1

Try this:

var bankButtonRefresh = '<a href="javascript:void(0)" onClick="refreshBankDataFunction({param:'+parentId+'})" class="btn-sm btn-primary permissionDeny pull-right" role="button">Refresh</a>';


function refreshBankDataFunction(obj){ //obj is the parentId
      alert('got into the function: ' + obj.data.param);
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you, I updated my action from onChange to onClick and this fix worked!
I am glad you got it working:) Please accept an answer in order to close the question.
0

Where you are building your link add an extra set of wrapping single quotes such as: onClick="refreshBankDataFunction(''+parentId+'')"

Comments

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.