Page 1 of 1

Using Ajax to enable Checkbox

Posted: Wed Jan 04, 2017 3:53 am
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?

Re: Using Ajax to enable Checkbox

Posted: Wed Jan 04, 2017 8:36 am
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.

Re: Using Ajax to enable Checkbox

Posted: Wed Jan 04, 2017 8:56 am
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.