Page 1 of 1

javascript forms

Posted: Wed May 11, 2011 9:30 pm
by jonathon
Hi,

I have been trying to find an example of a form liek that on autotrader http://www.autotrader.co.uk/. Basically say you pick a car make as BMW, then the next field will only populate BMW models. So once you've selected input 1, input 2 is filtered for you. I must not be searching for it very well in Google as I can't find any examples. I'd just like to see how it's done.

Does anyone have any good links?

Thanks

Re: javascript forms

Posted: Wed May 11, 2011 9:42 pm
by jacek
You need to make an AJAX request, to get all of the makes of car based on the selection. Then use this to populate the second box.

So using the cars example you would probably make a request to something.php?make=BMW where BMW would come from the selection. something.php would output a JSON encoded array which you would decode and use to fill in the next box.

Try searching for "javascript auto populate select" or something similar.

Re: javascript forms

Posted: Wed May 11, 2011 9:50 pm
by jonathon
Thanks Jacek,

Found a couple of examples. I knew what technologies were used and roughly how do it, but my searching was pretty bad. thanks :)

Re: javascript forms

Posted: Wed May 11, 2011 9:52 pm
by jacek
It's quite a common thing, you did pretty well to not find anything :lol:

Re: javascript forms

Posted: Wed May 11, 2011 9:53 pm
by jonathon
Thats what I was thinking. I put it down to it being late :lol:

Re: javascript forms

Posted: Wed May 11, 2011 9:55 pm
by jacek
jonathon wrote:Thats what I was thinking. I put it down to it being late :lol:
I was just about to record a tutorial :lol: Lets see how well that goes

Re: javascript forms

Posted: Wed May 11, 2011 9:58 pm
by jonathon
Haha,

Do it! I do enjoy your freestyling. Especially when you've got an afflication like a cold :lol: Kudos

Re: javascript forms

Posted: Wed May 11, 2011 9:59 pm
by jacek
jonathon wrote:Do it! I do enjoy your freestyling
Its a basics one too, no preperation :D

Re: javascript forms

Posted: Wed May 11, 2011 10:04 pm
by jonathon
It wouldn't be the same if you didn't get to 9 minutes and decide that you'd talked for a long time and then regretted it ;)