Using Ajax to enable Checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Using Ajax to enable Checkbox

Post by simonmlewis »

Hi.
I am building a tool that allows Administrators to enter a stock code, which runs an Ajax query to see if a "stock banner" is assigned to the product from the products DB table.
As they type, it searches. When it finds that stock code in the database, and sees it has a 'stockbanner' assigned, it displays that banner.

What I want to do, is to make a "Use Stock Banner Image" checkbox to appear when that image appears, so they can click it and use that, instead of having to upload a new banner.

I don't think I can just pop in a checkbox field into the Ajax results, below the <img> tag, as that runs outside of the <form>.
So I was wondering, a) if that is now possible to do, or b) if when there is a result found, it can set "disabled" to be enabled on the checkbox field that will always be displayed.

So user starts typing in the stock code... and if the image appears, the checkbox field basically "unlocks".

Possible?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Using Ajax to enable Checkbox

Post by Celauran »

Sure is. It will vary somewhat based on how things are currently implemented but you can enable/disable an existing checkbox or you can send back a new element containing all the fields and submit that.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Using Ajax to enable Checkbox

Post by simonmlewis »

Yes the ajax result does in deed work. It never use to in another script from a few years back. Possibly caused by a conflict.
Works a treat. Image shows, checkbox shows. Check it, and submit outer form, and it works.

Nice.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply