Can someone help with how to populate radio button in a table using javascript
Question
Question
Answer
Hi Vineela,
Sorry for the late, I was in weekend ^^.
First, check if your table have a checkbox with 1 value
Then find your field number. Let's see the preview then right click on your checkbox and select "Examine the item".
Then check your field number.
Then change it in the Javascript's code.
Replies
I have done it using Checkboxes
$(document).ready(function() {
$('.myTable').on('click', '.checkBox input', unCheck);
function unCheck() {
$('.checkBox input').removeAttr("checked");
$(this).prop("checked", true);
});
myTable is the class of the Table
checkBox is the class of the checkbox field "Display"
May I suggest that you will get better responses if you offer a more detailed description of what you trying to develop.
I want something like this, a static table with 3 rows and each row should have a radio button, the user can select only 1 row in a table by choosing any 1 radio button
I'm sure it's possible through Javascript. Would you get what you need by showing the table of information/input and then populate a separate radio button group from that they would use to make the selection? that may be easier.
No, I would like this in one table, all I need is JavaScript syntax to set the text of radio button to Option 1 for row 1.
Hi Vineela!
I created not radiobutton but a checkbox button ; then in my javascript, I said to use this checbox button like a radiobutton (means you can only choose 1 option).
//Page is laoded $(document).ready(function () { //Set Text of each box $('#Field3\\(1\\) label').text("Text 1"); $('#Field3\\(2\\) label').text("Text 2"); $('#Field3\\(3\\) label').text("Text 3"); //Set Value of each box $('#Field3\\(1\\) input').val("Value 1"); $('#Field3\\(2\\) input').val("Value 2"); $('#Field3\\(3\\) input').val("Value 3"); //Click on box $('[id^="Field3"] input').click(function(){ //Uncheck others checkbox Uncheck($(this).attr('id')); }); }); // Function Uncheck function Uncheck(e){ //Uncheck all checkbox with not this id $(':checkbox').each(function() { if($(this).attr('id') != e) { this.checked = false; } }); }
I changed mine to checkbox and tried with your code but it did not work. Checkboxes are not showing.
//Set Text of each box
$('#Field2\\(1\\) label').text("Text 1");
$('#Field2\\(2\\) label').text("Text 2");
$('#Field2\\(3\\) label').text("Text 3");
//Set Value of each box
$('#Field2\\(1\\) input').val("Value 1");
$('#Field2\\(2\\) input').val("Value 2");
$('#Field2\\(3\\) input').val("Value 3");
You have to assign a Choice Value, Just one such as "Y" for a checkbox to appear
If you don't want to see the Choice value you can hide it with JS
For the Options 1,2 and 3, I might just show the Row Label, but change the row name from Row{n} to Option {n}.
Actually in the case of Fixed Rows you can just enter the name for each row.
In my scenario, checkbox option is not the same for all three rows, it is option 1, option 2, option 3 for each row.
Other than the visual of the checkbox being selected for what line the user selects. How else is the value of the Checkbox used in your form/process?
nothing much, I can use your suggestion as a work around, display row label for option. wondering why Olivier's code is not working for me to display check box option.
Did you change the #Field3 to your field number?
Yes I did
Hi Vineela,
Sorry for the late, I was in weekend ^^.
First, check if your table have a checkbox with 1 value
Then find your field number. Let's see the preview then right click on your checkbox and select "Examine the item".
Then check your field number.
Then change it in the Javascript's code.
Great thanks Olivier. I did not add choice for checkbox and so it did not work.