cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the index of a row containing a checkbox in a Table.

0 Kudos

Hi,

In the layout of my Adobe Interactive form, there is a Table whose first column contains a checkbox and from the second column onwards, data from some internal table will be shown. The number of rows in the Table is not fixed, it is decided during runtime (based on the internal table's data). My requirement is, when the user will check a checkbox, the row index of the checkbox checked needs to be captured in the "click" event handler. I am using Javascript as the Form's language. How will I capture the selected checkbox's index using Javascript? Please suggest. Thanks in advance.

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

currentElement.index

Former Member
0 Kudos

Hi,

If you are using the old repeatable sub forms technique to display your table, then you can cheat a bit to get the index of the row. Let's say the layout hierarchy looks like:

+Subform1 (non-repeated, flowed)

++Subform2 (repeatable, flowed)

+++Checkbox1

+++Textfield1

......

In this case "Subform2" is the sub form which is repeated for each data element, i.e. elements in the context node. With this in place, try this code on click event handler of the checkbox:


   var rowIndex = Subform2.index;

So we are just getting the zero-based index of this sub form within a collection of sub forms. This will be the same as the row which contains the checkbox.

Regards,

Satyajit

former_member185086
Active Contributor
0 Kudos

Hi

From WebDynpro u can achieve by this way then get the current value from table

wdContext.nodeTestNode().setSelected(i, true);

From JavaScript (Just reference)

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj<i>.checked) {
			return radioObj<i>.value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj<i>.checked = false;
		if(radioObj<i>.value == newValue.toString()) {
			radioObj<i>.checked = true;
		}
	}
}

Best Regards

Satish Kumar

Edited by: satish jhariya on Sep 15, 2009 10:46 AM

Former Member
0 Kudos

Hi Anirban,

As i undertand you have a table with first column as checkbox and in the rest of the columns there are data. Also you have no. of rows coming up dynamically. Whenever user clicks on any checkbox you want to know which row is selected, if this is the problem, you can get the index of the row by writing a method on click of checkbox, to get the lead selection (current element) of the context node which is mapped to your table. Let me know if i have understood something different.

Gurmat