saseow
Posts: 744
|
Posted: 07/21/2011, 12:11 AM |
|
I have gone through this post so often (http://forums.codecharge.com/posts.php?post_id=60507) and still cannot get it to work:
I have an editable grid with a field (flavor_used) that holds a numeric value. Next to this I have an image that when clicked calls a js function that converts this number and puts the converted number back into the field. This works fine for a record form and for the first line of an editable grid but the ID extension (_2) in an editable grid has got me foxed.
The html code is:
<img id="Image1" name="Image1" alt="" src="images/O.png" onclick="ounce_to_gal('sugar_water_convertedflavor_used',document.getElementById('sugar_water_convertedflavor_used').value)"/>
The function is:
function ounce_to_gal(element_id,amount)
{
document.getElementById(element_id).value=amount*0.0078125;
}
My question is how on earth I can get and set the values of the flavor_used field in an editable grid?
Any help would really be appreciated!
|
|
|
scarvello
Posts: 64
|
Posted: 07/21/2011, 3:26 AM |
|
To refer each row field of Editable grid use document.getElementById with
{YOUR_FIELD}_{YOUR_EDITABLE_GRID:rowNumber} in JS.
|
|
|
datadoit
|
Posted: 07/21/2011, 6:01 AM |
|
That is correct.
It's apparent that you added the image control -after- the grid was
created, so CCS didn't put in the appropriate HTML for the image
control, which would be:
<img id="Image1_{GridName:rowNumber}" name="Image1_{GridName:rowNumber}"
alt="Image1_{GridName:rowNumber}">
Also when you're referring to row data field values, you'll need to
refer to that {GridName:rowNumber} value also.
document.getElementById('sugar_water_convertedflavor_used_{GridName:rowNumber}').value
|
|
|
saseow
Posts: 744
|
Posted: 07/21/2011, 6:15 AM |
|
Thank you both for the input.
I will have a look at this tonight and let you know the result.
Thanks again!!
|
|
|
saseow
Posts: 744
|
Posted: 07/21/2011, 8:10 AM |
|
I must be very dumb or very tired! I just cannot get this to work
I am now passing the grid name, the element and the row number to the functio and they all come through correctly. BUT... in the function a cannot set the value of the text box:
function ounce_to_gal(grid,element,row_num)
{
var result = grid + element + '_' + row_num;
document.getElementById(result).value=1234;
}
If I remove the row_num from result then the first row does change correctly?????
Should I build the grid again as it seems that the row numbers are not there???
|
|
|
datadoit
|
Posted: 07/21/2011, 10:46 AM |
|
You shouldn't have to rebuild. Just make sure the _{GridName:rowNumber}
attribute is in the places where it needs to be. If the grid was
originally created in -v4 of CCS, then I'd recommend rebuilding, since
grid functionality is a little different.
|
|
|
saseow
Posts: 744
|
Posted: 07/21/2011, 10:51 AM |
|
Thanks datadoit,
As you mentioned, the images were added afterwards. I will manually add the rowNumber stuff to them and see what happens.
Thanks again for your input, it is really appreciated!
|
|
|
saseow
Posts: 744
|
Posted: 07/22/2011, 12:40 AM |
|
Thank you very much datadoit!
The problem was exactly as you said:
When the grid was generated it left out the _{GridName:rowNumber} from some of the places and not others??? I am using Artisteer on this system so perhaps that messed things up although I cannot be sure.
Anyway, all fine now and thanks again!
|
|
|
datadoit
|
Posted: 07/22/2011, 5:31 AM |
|
You're welcome. I believe the rowNumber variable will only get placed
on input control values such as text boxes, checkboxes, etc., and not on
non-input control values such as labels, images, etc. Unverified.
|
|
|