dynamic creation of checkbox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2016 10:28 AM
Hi,
I want some value to be fetched from a table & display them as check-box in a catalog item.
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 10:10 AM
Hi Again Gurpreet,
NeverMind! I asked before I tried! All I needed to do is put the client script portion of the UI Page into an onLoad client script and it worked. I did import something from SHARE.. to."Create a catalog variable that renders as a table allowing multiple rows to be entered and saved." not sure if this is helping it work or if it is independent to it. I downloaded it thinking it would help me when I was looking for a solution to have dynamic checkboxes, but I didn't know how to use what it was adding. Anyways, Thanks so much for your solution information! Helped Greatly!!!
Trena

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 07:26 AM
Hi Gurpreet,
In regards to your statement to display on the RITM: "To represent these values on RITM form , we are adding selected categories to description variable. Here you need the class name of the checkbox input to get all checboxes in an array."
Can you provide an example of what you are referring to here?
I tried making the loading client script that puts the dynamic checkboxes in the Macro variable on the catalog submission form also run on the TASK & RITM, but it does not work. I used your script to get the selected (checked) boxes and save as a string of comma separated names and wrote them to a Multi Line Text variable on submit. When the RITM displays, the larger macro box displays with no checkboxes...the same client script should have ran, but it didn't work. After I can get the dynamic checkboxes to display again on the RITM, I was going to try to figure out a way to use the string value of selected checkboxes to again mark them as checked, but I can't get the empty boxes to display in the variable editor like they would on the submission form.
If you or anyone has done this successfully, can you share?
Thanks,
Trena
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 09:10 PM
Hi Trena,
To Store the values of the checkboxes in multiline variable, onSubmit Client script.
To display the selected checkboxes over RITM/Task you have to change the macro variable as well. Add additional attribute id to each of checkboxes and make it same as value attribute. Below instruction needs to be changed.
htmlString += '<td><input type="checkbox" class="checks" value="'+check+'" id="'+check+'">'+check+'</input></td>';
create an onload catalog client script. You already have the values(same as ids of the checkboxes) stored in a multi line variable (testMl in here) so simply split those values and set checkboxes to checked.
function onLoad() {
var values = g_form.getValue('testMl') ; //Multiline variable name where values stored.
values = values.split(',');
for(var i = 0; i < values.length ; i++ ){ //traversing over selected checkboxes
document.getElementById(values[i]).checked = 'checked' ;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 11:03 AM
Hi Gurpreet,
Thanks for the response! I have the solution as you've identified about created, but the setChecks onLoad function is abending on the document.getElementById(values[i]).checked = 'checked'; line
Based on the w3 Schools site using this functionality, they have the following:
function check() {
document.getElementById("myCheck").checked = true;
}
where the property checked is true or false. I was hoping that would fix it, but neither statement works.
This is what the DOM explorer of the RITM for one of the selected checkbox looks like:
When I open the RITM that was created from the submission, the Client Script runs to load the dynamic check boxes because I have the Client Script to run on the catalog item, Requested Item and the catalog task. Then the Client Script to setChecks runs and sees the number of items that were checked and in the for loop when the index is 0...1st time in loop, that statement document.getElementById(values[i]).checked = 'true'; (I've tried with "true", 'checked' and true without any quotes.) This statement has a problem and I am not sure what is wrong. Thoughts? This is the actual statement:
document.getElementById(values[i]).checked = 'checked'; Do you know if the statement actually needs a literal or can it be an array field? Also wonder about the quotes...if they need to be part of the array field or just the value without quotes. Struggling with this, so if there is any more you could offer?
Thanks,
Trena

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 11:38 AM
Hi Gurpreet,
Still looking at this and I'm wondering if I just need to rebuild the entire html area again like is done in the 1st client script, but change the checkbox to display as checked in the for loop of displaying the boxes. Not sure how to do it, but it seems like that is what needs to occur because doing a single update to check some box is not working and is erroring out my page. If I can get it to work, I will respond again. If you can think of any other update that I can make also, please advise.
Thanks,
Trena