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???

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.

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

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

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

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

Can you show me the html of your checkboxes?

What is your email??? I can send you the files

Just sent you the code via Private Message

Ok let me have a tinker...

Thanks

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);
            }

I dont think im following you

I was using the .prop to pass check the check box
first time I do this

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

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

Ok let me check in the monring, off to bed now.

Good night and thanks

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.

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.

Ok let me take a look...

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.