0

Im trying to check checkboxes based on a cfselect selection. Im trying .prop but is not passing the info to the check box
I added p#testing.html to see if the query was working and it is passing info as text based on selection but not to checkbox

function roleCallback(text)
            {
                $('p#testing').html(text);
                var roleInfo = new Array();
                roleInfo = text.split('|');
                var roleInfoLength = roleInfo.length;
                for (var i = 0; i < roleInfoLength; i++) {
                    $('input#grant_AppId' + i).prop('checked', true);
                    $('input#revoke_AppId' + i).prop('checked', false);
                }
            }

Any ideas???

2
Contributors
21
Replies
39
Views
2 Years
Discussion Span
Last Post by yankeefan24
0

Looks ok at a glance - are you able to provide some html as well so I can have a play? Also an example of what text contains when the function is called.

0

Text screenshot attached,

here are the functions

function RoleLookup()
            {
                ColdFusion.Ajax.submitForm('UserAccessForm', 'UserLookup.cfm?role=true', roleCallback, errorHandler);
            }
            function






function roleCallback(text)
            {
                $('p#testing').html(text);
                var roleInfo = new Array();
                roleInfo = text.split('|');
                var roleInfoLength = roleInfo.length;
                for (var i = 0; i < roleInfoLength; i++) {
                    $('input#grant_AppId' + i).prop('checked', true);
                    $('input#revoke_AppId' + i).prop('checked', false);
                }

front end

<p>Please give me applications for the role of:
                    <cfselect name="UserRoleSelect" query="UserRoles" display="Name" value="id" onChange="RoleLookup()">
                        <option value="" selected>-- Select --</option>
                    </cfselect>
                </p>
                <p id="testing">&nbsp;</p>

Screenshot.png

0

Have you debugged it? Is roleCallback actually getting called and if so what is the value passed into it?

0

Have not debbuged but this is the results im getting when selecting from dropdown 2|6 when choosing physician
and 1|6 when choosing nurse

0

Ok right that is what $('p#testing').html(text) is for.

Can you show me the html of your checkboxes?

0

Ok this is an educated guess rather than having actually worked through it properley but do you need the code below instead?

            for (var i = 0; i < roleInfoLength; i++)
            {
                $('input#grant_AppId' + roleInfo[i]).prop('checked', true);
                $('input#revoke_AppId' + roleInfo[i]).prop('checked', false);
            }
0

Look at the difference between your code and mine:

for (var i = 0; i < roleInfoLength; i++)
{
    $('input#grant_AppId' + i).prop('checked', true);
    $('input#revoke_AppId' + i).prop('checked', false);
}



for (var i = 0; i < roleInfoLength; i++)
{
    $('input#grant_AppId' + roleInfo[i]).prop('checked', true);
    $('input#revoke_AppId' + roleInfo[i]).prop('checked', false);
}

Ie roleInfo[i] instead of just i

Edited by DaveAmour

0

Same result, is just adding the text 2|6, 1|6 depending on selection. Is not yet checking the proper checkbox

0

Ok so I don't do coldfusion so can't run your code but I can definatley fix this for you with a bit more info!

Can you show me a screenshot of these checkboxes and the rendered html - ie view the source in your browser.

Also what data can come back into text - is it always 2 numbers for example.

In plain English explain what these numbers should do with your checkboxes - I believe the code just isn't doing what you want so explain to me what the intent of your algorithm is and I can fix it.

0

Just sent you the source code on a PM. Attached is a print screen of the check boxes. Number 1 and 2 are the User role on the DB 1 being nurse and 2 being the physician the 6 will be the AppId, AppId each app is represented by a chechbox in the form.

0

Your checkboxes have name attribute but need an id as well!

In jquery when you use # that looks for an id, not a name.

id tends to be used client side and name is what goes into postbacks. You can have both.

Edited by DaveAmour: typo

0

How can I do that if the checkboxes are being called from the DB
Ill send you the code via PM

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.