View Full Version : Help with auto-completion of input boxes

02-13-2011, 06:02 PM
It seems I can't code my way out of a paper bag.. I am, however usually good enough with google to find what I want but I keep finding the wrong information :(

I'm hoping some of the ajax/php gurus out there can help me out a bit.

Basically I'm trying to make a inventory tracker to scan out products from my warehouse. The idea being that when a product is sold the barcode and serial numbers of the product will be scanned so I can determine exactly what is no longer in the warehouse.

So I've got a 'Products' database with the following fields: ProductUPC (barcode) ProductPartNumber (unique 6 digit code for each product) ProductDescription (description of the product).

On my HTML form I've got a bunch of text boxes (UPC, Part Number, Description & Serial Number).

I want to be able to scan the UPC of the product and have the Part Number & Description fields auto-complete with AJAX/PHP wizardry so that these fields don't need to be entered manually..

Then all that needs to be done is for the serial number barcode to be scanned and boom the results end up in the 'Requests' table :)

Sounds relatively straightforward but I keep getting auto-suggest stuff for the one field :(

Any help is hugely appreciated :D

02-13-2011, 06:54 PM
What you're asking for is as simple as it gets: Once you have the UPC, you start an AJAX request to get that other data from the database (say, as JSON); then you put it into the fields. Unless I misunderstand, that's as basic an AJAX call as you could get, and there's not much to it.

In all honesty, you don't even need that AJAX call. Just do a normal form submission for the UPC. Your server script can do with it whatever it has to do, like look up the product and put something in the 'Requests' table. Then it can send back the info to the browser, if you're still interested in seeing that.

Also, it sounds like bad design, if you need all the data of a product in order to put it into another table. I don't really know your business logic, but typically you would just put the primary key of the product into another table, in order to keep your database normalized (and not to add redundant data).

02-13-2011, 08:57 PM
Thanks for the awesome response! :)

I'm terrible at coding/web development - this stuff is on an internal server and it's not going to have tons of records so I'm not too bothered about efficiency/performance.

The purpose of the information being in the browser is so that whoever inputting the data can verify it before submission.

Any links to some sample code?

Cheers :)

02-14-2011, 05:48 PM
I'm not sure what sample code I should point you to, since what you want to do, while quite simple, does involve the whole spectrum of technologies. I suppose you're fine with the PHP/MySQL part; for the client side part (AJAX, DOM manipulation), you could look into jQuery, which should make the task quite easy.

Of course, if you're really terrible at coding, you might want to consider hiring a professional.

02-15-2011, 08:39 PM
Thanks again for the response..

The annoying thing is - I had something in jQuery that worked with one of the fields which now I'm thinking would be acceptable.. I seem to have lost it :'(

Ahhh well - I'll keep looking.

I'm not really prepared to pay for this as it's my employer that will benefit and as they are pretty much one of the biggest companies in the world I don't want to be paying for it ;)


02-15-2011, 08:46 PM
... if you're looking for a jQuery autocomplete, I use this (http://jqueryui.com/demos/autocomplete/) one and I'm very happy with it.