开发者

How to identify the current row in an Apex Tabular Form?

Friends,

I have written the following JavaScript to ascertain which row of an tabular form the user is currently on. i.e. they have clicked a select list on row 4. I need the row number to then get the correct value of a field on this same row which I can then perform some further processing on.

What this JavaScript does is get the id of the triggering item, e.g. f02_0004 This tells me that the select list in column 2 of row 4 has been selected. So my Javascript gets just the row information i.e. 0004 and then uses that to reference another field in this row and at the moment just output the value to show I have the correct value.

<script language="JavaScript" type="text/javascript">
   function cascade(pThis){      
      var row = getTheCurrentRow(pThis.id);
      var nameAndRow = "f03_" + row;
      var costCentre = $x(nameAndRow).value;
      alert("the cost centre id is " + costCentre);

}
   /开发者_如何学Go/ the triggerItem has the name fxx_yyyy where xx is the column number and 
   // yyyy is the row. This function just returns yyyyy    
   function getTheCurrentRow(triggerItem){   
      var theRow = triggerItem.slice(4);
      return theRow;         
}

Whilst this works I can't help feeling that I must be re-inventing the wheel and that either, there are built-in's that I can use or if not there maybe a "better" way?

In case of need I'm using Apex 4.0

Thanks in advance for any you can provide.


Well, what you have described is exactly what I typically do myself!

An alternative in Apex 4.0 would be to use jQuery to navigate the DOM something like this:

var costCentre = $(pThis).parents('tr').find('input[name="f03"]')[0].value;

I have tested this and it works OK in my test form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜