RE: PHP, SQL, AJAX, JS and populating a SelectBox?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ajax can be made to use POST by adding

req.open("POST", url, true); // true creates an asynchronous connection
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

where req is the XHR object

Also why not use the same style of formatting for the response as the
request uses... eg:

foo=My Foo&bar=My Bar&wibble=My Wibble

The first value is the option value and the second is the option text

FWIW I think that using innerHTML is a bad idea as the elements created
aren't included in the DOM tree... creating the elements using the DOM is a
much better idea... It may be more lengthy by that can be cut down some with
clever scripting :)

HTH

Dan

-------------------
http://chrome.me.uk
 

-----Original Message-----
From: Daevid Vincent [mailto:daevid@xxxxxxxxxx] 
Sent: 18 March 2006 22:45
To: php-general@xxxxxxxxxxxxx
Cc: 'tedd'
Subject: RE:  PHP, SQL, AJAX, JS and populating a SelectBox?

No. All of the examples I find are like the 'google' style suggest-thingy.

I want to dynamically (AJAX) populate an actual:

<select>
	<option value='1'> foo 
	<option value='2'> bar
	<option value='3'> fee
	<option value='4'> fum
</select> 

Basically the core problem is passing back an 'array' of data from mysql
into JS to make the box.

What I've 'hacked' together so far is that I return my values like so from
PHP/mySQL to JS AJAX:

$tmp = "1|foo|2|bar|3|fee|4|fum";

And then in JS, I do this:

tokens = tmp.split('|');

Then use a for(i++2) loop and build up the options (key and value) of the
select box.

But, to me this seems like a hack.

Plus I'm a little worried that there is going to be a size limit of
characters or data or something? After all, AFAIK AJAX uses $_GET method
right? Not $_POST. So I think GET has a limit of like 1024 characters,
whereas POST doesn't have that limit.

My select box could have potentially thousands of items in it. Say for
example, IP addresses. I have supporting select boxes to filter by ranges,
or groups, or whatever, but there's nothing restricting a user from NOT
using them, and just wanting to see ALL the IP addresses...

So, I guess what I'm asking, is, is this the right way to solve this
challenge, or is there a better/more accepted way?

> -----Original Message-----
> From: tedd [mailto:tedd@xxxxxxxxxxxx] 
> Sent: Saturday, March 18, 2006 1:02 PM
> To: php-general@xxxxxxxxxxxxx; Daevid Vincent
> Subject: Re:  PHP, SQL, AJAX, JS and populating a SelectBox?
> 
> >I need to dynamically update a select box
> >with results from a SQL database using AJAX,
> >but I can't find a single example of how to do this.
> >
> >Basically I have a text input field, and a select box.
> >As someone types in the input field,
> >I want the select box to fill in the results of matches.
> >
> >I can fill in a <DIV> (as per the ten million examples out there)
> >and that's all fine and dandy, but way too simplistic for 
> what I need.
> 
> Select Box?
> 
> Do you mean a Selection List, that will change as the user types in 
> an input field like this:
> 
> http://www.itsyourdomain.com/
> 
> Just type domain name into the search box -- is that what 
> you're looking for?
> 
> tedd
> -- 
> --------------------------------------------------------------
> ------------------
> http://sperling.com
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


__________ NOD32 1.1450 (20060318) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux