jerry
Posts: 16
|
| Posted: 01/15/2007, 7:59 PM |
|
i need to populate some fields in an editable grid once a value in a listbox is selected. i followed an example in CCS - retrieving fields values but it doesn't work i think because in my case its editable grid.
wondering if someone has sample code i can use.
|
 |
 |
marcwolf
Posts: 361
|
| Posted: 01/16/2007, 6:58 PM |
|
Hi Jerry
Ok - when you make an editable grid in CSS you make a row with say the following control
NAME, ADDRESS, POSTCODE
When CSS make the grid you will see the following fields in the grid. When doing this it is a VERY good idea to copy the {field_name} entry also into the ID field in the format tab.
NAME_1, ADDRESS_1, POSTCODE_1
NAME_2, ADDRESS_2, POSTCODE_2
NAME_3, ADDRESS_3, POSTCODE_3
With this information (and javascript) you can so the following (Psuedo code)
Putting a default into the POSTCODE field.
Make a loop called x. Loop x through 1 to 10. within loop do this "POSTCODE_" + x
Then do a document.getelementbyid("POSTCODE_" + x ).value = 4000
To address other fields in the row.
Get the id of the selected field (POSTCODE_1), get the number from the end ( 1 ) Then do a getelementbyid("ADDRESS_" + 1 ) and you now can work with any field in the row.
Hope this gives you some inspiration.
Take Care
Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
|
 |
 |
marcwolf
Posts: 361
|
| Posted: 01/16/2007, 7:05 PM |
|
Oh - here is some code.
Here a simple function to retrieve the ROW ID from a editable grid
// Get Editable Grid Row from Control
// Pass Control as object (THIS), returns back string of "_x" where x is row
function GetRowID(Field1){
var fldname = ""; var fldname1 = ""; var fldloc = -1;
fldname = Field1.name; fldloc = fldname.lastIndexOf("_"); // work out the calling field and extract its index
if (fldloc <= 0) {return "";} // Not an Index.. Return a Blank, safe to append to control name
else
{return fldname.substring(fldloc,fldname.length);} // returns back the '_x' where x is the row
}
For example - here is a simple routine that calls a Calculation routine for totalling a column in an editable grid
function ReCalc() {
var result = true;
var amt1 =0;
var amt =0;
var tmp;
for (var j = 1; j <12; j++) {
// checkf for existance of the element
if (eval("document.forms[\"formname\"].price_total_" + j)) {
tmp = "CalcPrice(document.forms[\"formname\"].price_total_" + j + ")";
eval(tmp);
}
}
}
Editable Grid rows start at 1. And you have a pretty good idea of how many rows a grid has.
and remember - YOU MUST POPULATE A FIELD'S ID!!.. (Hint Hint to CCS - it makes Javascript SO much easier)
Take Care and Enjoy
Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
|
 |
 |
jerry
Posts: 16
|
| Posted: 01/17/2007, 10:42 PM |
|
hi dave
thanks for replying. i am a novice with CCS and javascript so excuse my ignorance.
referring to your code in GetRowID function, i've place an onchange event on my listbox 'ProductID' when this is triggered the function is called and returns a value x (row_id of editable grid) is this correct?
|
 |
 |
marcwolf
Posts: 361
|
| Posted: 01/18/2007, 2:19 AM |
|
Hi Jerry
Thats right.
Now - you can add that value to the ID of another field say NAME so if the returned number is 3 you will get
NAME_3
With that you can hen do a document.getelementbyid('NAME_3') and have a reference to the next field in the table row.
Hope this gives some more insight. Don't worry about starting :> we were all there at one time
Take Care
Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
|
 |
 |
|