Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am selecting some checkboxes and then sending the ID of those checkboxes to a button in a HTML page

After selecting the checkboxes the IDs are stored in an object selectedIDs. This object is passed to the button. When I debugged and checked, the object received the IDs as I want i.e. '1','2','3'

But as soon as it is passed to the button it is received as '1,2,3' but I want them to be receives as '1','2','3'

What I have tried:

I tried few solutions but none of them worked
1. <button type="button" onclick="save('<%- selectedIDs %>')">Save</button>
2. <button type="button" onclick="save(['<%- selectedIDs %>'])">Save</button>

I am not able to render the IDs as I want. How can I do it?
Posted
Updated 30-Dec-18 17:15pm

1 solution

Not clear how the selectedIDs is being generated. I think the following
save(['<%= selectedIDs %>'])
should work if
selectedIDs = '1','2','3'


A quick work around, in the save function, use the split() function to split the selectedIDs into array object

String.prototype.split() | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900