This topic is locked
[SOLVED]

 Check boxes on listpage programatically

1/8/2014 10:55:13 AM
PHPRunner General questions
W
wpl author

Hi all,
somebody can show me how to go about to set the status of the checkboxes on listpage to "checked" programatically, depending on if a certain field is also checked or not?
In the meantime, I found a solution that fits my needs. In the "AfterRecordProcessed" event, I have the following code:



if ($data["someField"]==1)

{

$record["checkbox_attrs"] .= ' checked="checked"';

}
Sergey Kornilov admin 1/8/2014

If you are talking about checking off selection check boxes here is how this can be done.
In Javascript OnLoad event you can use something like this to make record with key column value 5 selected:

$("input[name='selection[]'][value='5']").attr('checked','checked');


Now, if you only need to make certain records selected based on value of some database field you need to prepare a list of IDs in one of server side event and pass it to Javascript OnLoad event via proxy object.
More info on passing data from PHP to Javascript:

http://xlinesoft.com/phprunner/docs/how_to_access_php_variables.htm

W
wpl author 1/9/2014

Sergey,
thanks for your input. That's more elegant, I guess I will give it a try.

Sergey Kornilov admin 1/9/2014

Found even a bit more elegant option that will work even without passing data from PHP to Javascript. Here is the example of automatically selecting records with Horsepower field value more than 200:

var recsId = pageObj.inlineEdit.getRecsId();

for (i in recsId) {

if (Number($("span[id='edit"+recsId[i]+"_Horsepower']").html())>200)

$("input[name='selection[]'][id='check1_"+recsId[i]+"']").attr('checked','checked');

}
W
wpl author 1/9/2014



Found even a bit more elegant option that will work even without passing data from PHP to Javascript. Here is the example of automatically selecting records with Horsepower field value more than 200:

var recsId = pageObj.inlineEdit.getRecsId();

for (i in recsId) {

if (Number($("span[id='edit"+recsId[i]+"_Horsepower']").html())>200)

$("input[name='selection[]'][id='check1_"+recsId[i]+"']").attr('checked','checked');

}



Sergey,
please stop to develop even more elegant solutions! I will always have to change my code after you had a new idea <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=73592&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=73592&image=2&table=forumreplies' class='bbc_emoticon' alt=':D' /> .
Thanks

Sergey Kornilov admin 1/9/2014

This one is good enough to stay <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=73594&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

W
wpl author 1/9/2014



This one is good enough to stay <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=73596&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


Sergey,
for sure! But the icing on the cake could be: if the field you need to query is represented by a checkbox, you would have to query the name of the respective image, ie 'check_yes.gif' or 'chec_no.gif'. How to go for that?