Page 1 of 1

Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 10:05 am
by dieter
Hello,
i have a subfile with a checkbox. When the user clicks on a row i want to set the value of the checkbox in that row by JavaScript. If the user directly clicks the checkbox all works fine. But i want to switch the checkbox value also when the user clicks somewhere in the row. I tried to do that with the onrowclick event of the grid.
The name of the checkbox element is "auswahl". So this is my code:
changeElementValue("auswahl", "J");

I think the problem is that in a grid the real element ID is not auswahl but somethink "auswahl.1", "auswahl.2", depending of the grid row. Is that right?
In the documentation i found a method "getCellValue". Is there a method like "setCellValue" or something like this?

Dieter

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 10:09 am
by emhill
Deiter,

We are doing this numerous places. Here is the code for the onrowclick event. SEL is the field name for the checkbox. We are placing an "X" in the field when the box is checked and a blank when not checked:
=============================================
var optId = "SEL." + row;

if (getObj(optId)){

if (!getObj(optId).checked) {
getObj(optId).checked = true;
changeElementValue(optId, "X");
}
else{
getObj(optId).checked = false;
changeElementValue(optId, "");
}
}
=============================================

Hope this helps!!!!

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 10:11 am
by Scott Klement
Yes, that is correct, you need to append the record number to the id. So it'd be auswahl.1, auswahl.2, etc.

No, there isn't anything like a setDataValue() API. You need to do it by calculating the id.

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 11:13 am
by dieter
Thank you for your posts. I just tried it and it works. But after my try i have recogneized that this is not exactly what i need. I didn't tell you that there also is JavaScript Code in the onclick event of the checkbox. Sorry. I want to execute that code also. Is there a possibility to simulate a click on the checkbox? I think pui.click() only works für buttons. E.G. i tried pui.click("auswahl.1") . But this does not work.

Dieter

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 11:19 am
by Scott Klement
I'm not aware of an easy way to "simulate" a click on the checkbox.

I would suggest putting the code that's running in the 'onclick' event of the checkbox into a separate JavaScript function (perhaps in a separate JavaScript file). Then you could call this function both from the onclick of the checkbox and from the code that's setting the value programatically.

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 11:27 am
by dieter
Thank you Scott. Good idea.
I will try.

(Again special thanks to Eric. Your code gave me some new ideas ...)

Dieter

Re: Update an element in a grid by JavaScript

Posted: Mon Aug 18, 2014 2:50 pm
by emhill
Dieter,

Maybe create a hidden button on the grid row that has the onclick event handle what you need when the checkbox is checked. Change your onclick event for your checkbox to pui.click("hiddenbutton") and in the onrowclick event add the pui.click("hiddenbutton") under the condition where the checkbox is checked.

Just a thought....

Re: Update an element in a grid by JavaScript

Posted: Tue Aug 19, 2014 3:02 am
by dieter
Hello Eric,
cool idea...
I like such cool ideas :-)

Thank you and best regards from Germany.

Dieter