Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading combo boxes

Status
Not open for further replies.

roontoon

MIS
Sep 25, 2010
15
US
Hi how can I dynamically load a combo box from a mysql db? I need to load one combo box with room numbers and then when a room number is selected it will display asset numbers of items in that room in a second combo box. I have seen various AJAX code snippets but I have not found any examples that work. I am a newbie and still learning PHP so if this question is obvious consider the source. Thanks for any help.

d
 
@jpadie

OK I went back and tried what you suggested. I fully copied your full code from above and replaced line 66 with elem.remove(i); I have tested both on a Mac with Safari and on Windows XP with IE. Both with mixed results. So far neither will reload the asset number for the room selected. Would there be any server or policy settings on the windows side that might be causing problems?

Safari on Mac
1.png


IE on XP

2.png


3.png


4.png
 
It does but there is a trailing comma, not sure if that will be an issue.
Jpadie's method of taking care of the comma is a good one, I simply did it in the JS by setting the loop to -2. So it ignores the last entry in the array we produce.

Code:
for(var i=0;i<=[b][blue]resultsArray.length-2[/blue][/b];i++){

Couple of questions. I am assuming that this script lives within the script tags in the file referenced above. Also what triggers it? Lastly can this code as well as the AJAX setup so it is generic? Just thinking ahead incase I find this useful (pretty sure I will). Thanks

The AJAX script which include the JS script to recreate the dropdown lives in the same page as the html dropdowns that's the entire point.

The trigger is the onChange event of the dropdown. You still don't seem to have understood how this works.


Code:
<html>
...
<script>
function populate(){
Ajax code, and populating code as shown above. 
}
</script>
...
<body>

<select name="dropdonwn1" onchange="populate();">
...
</select>

<select name="dropdonwn2">
...
</select>

And

Code:
<?PHP
PHP code to get relevant results from Database. 
?>


The onChange event triggers our JS function which holds the Ajax code that calls up the PHP script. The PHP script obtains the results we need by using the value we passed to it through the GET array. It then outputs its values to screen, which our Ajax script can then retrieve.

THe Javascript can then take the results that the Ajax script receives to populate the dropdown.


As far as the generic question goes, I don;t quite understand what you are asking.

The Ajax code is as generic as they come, its simply a conduit to get the results. Whatever you get is provided by the PHP script, and what you do with them in your Javascript is up to you.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
@Rontoon

I am unable to reproduce your experience on any browser/OS combo to which I have access.

The results I get are

Screen%20Shot%202011-09-06%20at%2010.04.35%20AM.png

Screen%20Shot%202011-09-06%20at%2010.04.49%20AM.png

Screen%20Shot%202011-09-06%20at%2010.04.58%20AM.png

Screen%20Shot%202011-09-06%20at%2010.05.08%20AM.png


changing the script for debug purposes so that you can see (without firebug) what is being returned from the php script shows this

[tt]

Room: 135
Value Text

G42593 G42593
G42599 G42599
G42600 G42600
G42609 G42609
J72662 J72662
J72667 J72667
J72670 J72670
J72674 J72674
J72678 J72678
J72679 J72679
J72680 J72680
J72684 J72684
M35253 M35253
M68784 M68784
M68785 M68785
M68786 M68786
M68787 M68787
M68788 M68788
M68789 M68789
M68790 M68790
M68791 M68791
M68792 M68792
M68793 M68793
M68794 M68794
M68795 M68795
M68796 M68796
M68797 M68797
M68798 M68798
M68799 M68799
M68800 M68800
M68801 M68801
M68802 M68802
M68803 M68803
M68804 M68804
M68805 M68805
M68806 M68806
M68807 M68807
M68808 M68808
M68809 M68809

Room: 410
Value Text

M35295 M35295

Room: 123
Value Text

M00871 M00871
M00872 M00872
M00873 M00873
M00874 M00874
M00875 M00875
M00876 M00876
M00877 M00877
M00878 M00878
M00879 M00879
M00880 M00880
M00881 M00881
M00882 M00882
M00883 M00883
M00884 M00884
M00885 M00885
M00886 M00886
M00887 M00887
M00888 M00888
M00889 M00889
M00890 M00890
M00891 M00891
M00892 M00892
M00893 M00893
M00894 M00894
M00896 M00896
M00897 M00897
M00898 M00898
M00899 M00899
M00900 M00900
M00901 M00901
M60726 M60726

Room: 108
Value Text

G15314 G15314
G27652 G27652
G27669 G27669
G27680 G27680
G27681 G27681
G27695 G27695
G27712 G27712
G27715 G27715
G27735 G27735
G27740 G27740
G27742 G27742
G27743 G27743
G27750 G27750
G27752 G27752
J72661 J72661
M00895 M00895
M06182 M06182
M06188 M06188
M35233 M35233
M35258 M35258
M35280 M35280
M35283 M35283
M35287 M35287
[/tt]

the code used to generate this is as follows. I changed the POST to GET, but it should not matter.
Code:
[COLOR=#990000 ]<?[/color]PHP 
[i][COLOR=#9A1900 ]//database settings[/color][/i]
[COLOR=#009900 ]$dbhost[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'localhost'[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$dbuser[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]''[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$dbpass[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]''[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$dbname[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'help_desk'[/color][COLOR=#990000 ];[/color]

[i][COLOR=#9A1900 ]//Connect to MySQL Server[/color][/i]
[COLOR=#009900 ]$connection[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_connect[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$dbhost[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$dbuser[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$dbpass[/color][COLOR=#990000 ]);[/color]

[i][COLOR=#9A1900 ]//Select Database[/color][/i]
[COLOR=#009900 ]$db[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_select_db[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$dbname[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_error[/color][/b][COLOR=#990000 ]());[/color]

[b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]getRoomEquipment[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$room[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][COLOR=#009900 ]$sql[/color][COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"SELECT bpi_tag FROM `hesk_equipment` WHERE `room`='"[/color] [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]mysql_real_escape_string[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$room[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]"'"[/color][COLOR=#990000 ];[/color]
[tab][COLOR=#009900 ]$result[/color][COLOR=#990000 ]=[/color][COLOR=#009900 ]@mysql_query[/color][COLOR=#990000 ]([/color][COLOR=#009900 ]$sql[/color][COLOR=#990000 ]);[/color]
[tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[tab][b][COLOR=#0000FF ]while[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_fetch_assoc[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color][COLOR=#990000 ])):[/color]
[tab][tab][COLOR=#009900 ]$return[/color][COLOR=#990000 ][][/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'text'[/color][COLOR=#990000 ]=>[/color][b][COLOR=#000000 ]htmlspecialchars[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'bpi_tag'[/color][COLOR=#990000 ]]),[/color] [COLOR=#FF0000 ]'value'[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'bpi_tag'[/color][COLOR=#990000 ]]);[/color]
[tab][b][COLOR=#0000FF ]endwhile[/color][/b][COLOR=#990000 ];[/color]
[tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$return[/color][COLOR=#990000 ];[/color]
[COLOR=#FF0000 ]}[/color]

[b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_REQUEST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'action'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]&&[/color] [COLOR=#009900 ]$_REQUEST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'action'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]==[/color] [COLOR=#FF0000 ]'getEquipment'[/color][COLOR=#990000 ]):[/color]
[tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_REQUEST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'room'[/color][COLOR=#990000 ]])):[/color]
[tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'result'[/color][COLOR=#990000 ]=>[/color]false[COLOR=#990000 ]);[/color]
[tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][COLOR=#009900 ]$equipment[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]getRoomEquipment[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_REQUEST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'room'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$equipment[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ]):[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'result'[/color][COLOR=#990000 ]=>[/color]false[COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'error'[/color][COLOR=#990000 ]=>[/color][b][COLOR=#000000 ]mysql_error[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'result'[/color][COLOR=#990000 ]=>[/color][COLOR=#FF0000 ]'ok'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'data'[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$equipment[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][b][COLOR=#0000FF ]echo[/color][/b] [b][COLOR=#000000 ]json_encode[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$return[/color][COLOR=#990000 ]);[/color]
[tab][b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ];[/color]
[b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$sql[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"SELECT DISTINCT `room` FROM `hesk_clients` WHERE `room` > ''"[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_query[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$sql[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$connection[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_error[/color][/b][COLOR=#990000 ]());[/color]

[COLOR=#990000 ]?>[/color]
[COLOR=#990000 ]<![/color]DOCTYPE html PUBLIC [COLOR=#FF0000 ]"-//W3C//DTD XHTML 1.0 Transitional//EN"[/color] [COLOR=#FF0000 ]"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[/URL][/color][COLOR=#990000 ]>[/color]
[COLOR=#990000 ]<[/color]html[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]head[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]title[COLOR=#990000 ]>[/color]Combobox Test[COLOR=#990000 ]</[/color]title[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]meta http[COLOR=#990000 ]-[/color]equiv[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"Content-Type"[/color] content[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text/html; charset=utf-8"[/color][COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]script type[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text/javascript"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]populate_dropdwn2[/color][/b][COLOR=#990000 ]([/color]elem1[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] xmlhttp[COLOR=#990000 ];[/color]   
[tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color]window[COLOR=#990000 ].[/color]XMLHttpRequest[COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab]xmlhttp [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [b][COLOR=#000000 ]XMLHttpRequest[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]else[/color][/b] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab]xmlhttp [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [b][COLOR=#000000 ]ActiveXObject[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"Microsoft.XMLHTTP"[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab]xmlhttp[COLOR=#990000 ].[/color]onreadystatechange[COLOR=#990000 ]=[/color][b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color]xmlhttp[COLOR=#990000 ].[/color]readyState [COLOR=#990000 ]==[/color] [COLOR=#993399 ]4[/color] [COLOR=#990000 ]&&[/color] xmlhttp[COLOR=#990000 ].[/color]status [COLOR=#990000 ]==[/color] [COLOR=#993399 ]200[/color][COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] results[COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]eval[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'('[/color] [COLOR=#990000 ]+[/color] xmlhttp[COLOR=#990000 ].[/color]responseText [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]')'[/color] [COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][tab]
[tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color]results[COLOR=#990000 ].[/color]result [COLOR=#990000 ]==[/color] [COLOR=#FF0000 ]'ok'[/color][COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] elem [COLOR=#990000 ]=[/color] document[COLOR=#990000 ].[/color][b][COLOR=#000000 ]getElementById[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'asset_no'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][tab][tab]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]//delete all current options[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]for[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]var[/color][/b] i [COLOR=#990000 ]=[/color] elem[COLOR=#990000 ].[/color]length[COLOR=#990000 ]-[/color][COLOR=#993399 ]1[/color][COLOR=#990000 ];[/color] i [COLOR=#990000 ]>=[/color] [COLOR=#993399 ]1[/color][COLOR=#990000 ];[/color] i[COLOR=#990000 ]--[/color] [COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][tab][tab]elem[COLOR=#990000 ].[/color][b][COLOR=#000000 ]remove[/color][/b][COLOR=#990000 ]([/color]i[COLOR=#990000 ]);[/color][i][COLOR=#9A1900 ]// = null;[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/*** debug ***/[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] debugElem [COLOR=#990000 ]=[/color] document[COLOR=#990000 ].[/color][b][COLOR=#000000 ]getElementById[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'debug'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][tab][tab]debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]=[/color] debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]'<pre>Room: '[/color] [COLOR=#990000 ]+[/color] elem1[COLOR=#990000 ][[/color]si[COLOR=#990000 ]].[/color]value [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]'\nValue\tText</pre>\n'[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/******/[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]//now add in new options[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#0000FF ]for[/color][/b] [COLOR=#990000 ]([/color]i [COLOR=#990000 ]=[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ];[/color] i [COLOR=#990000 ]<[/color] results[COLOR=#990000 ].[/color]data[COLOR=#990000 ].[/color]length[COLOR=#990000 ];[/color] i[COLOR=#990000 ]++[/color] [COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][tab][tab]elem[COLOR=#990000 ].[/color]options[COLOR=#990000 ][[/color]elem[COLOR=#990000 ].[/color]length[COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [b][COLOR=#000000 ]Option[/color][/b][COLOR=#990000 ]([/color]results[COLOR=#990000 ].[/color]data[COLOR=#990000 ][[/color]i[COLOR=#990000 ]].[/color]text[COLOR=#990000 ],[/color] results[COLOR=#990000 ].[/color]data[COLOR=#990000 ][[/color]i[COLOR=#990000 ]].[/color]value[COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/** debug **/[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][tab]debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]=[/color] debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]'<pre>'[/color] [COLOR=#990000 ]+[/color] results[COLOR=#990000 ].[/color]data[COLOR=#990000 ][[/color]i[COLOR=#990000 ]].[/color]text [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]"\t"[/color] [COLOR=#990000 ]+[/color] results[COLOR=#990000 ].[/color]data[COLOR=#990000 ][[/color]i[COLOR=#990000 ]].[/color]value [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]"\n"[/color] [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]"</pre>"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/****/[/color][/i]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/** debug **/[/color][/i]
[tab][tab][tab][tab][tab][tab][tab]debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]=[/color] debugElem[COLOR=#990000 ].[/color]innerHTML [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]"</pre><hr />"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][tab][tab][tab][i][COLOR=#9A1900 ]/****/[/color][/i]
 
[tab][tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color] [b][COLOR=#0000FF ]else[/color][/b] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][tab][b][COLOR=#000000 ]alert[/color][/b] [COLOR=#990000 ]([/color]results[COLOR=#990000 ].[/color]error[COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color][tab][tab]   
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] si [COLOR=#990000 ]=[/color] elem1[COLOR=#990000 ].[/color]selectedIndex[COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color]si [COLOR=#990000 ]>[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] val [COLOR=#990000 ]=[/color] elem1[COLOR=#990000 ][[/color]si[COLOR=#990000 ]].[/color]value[COLOR=#990000 ];[/color]
[tab][tab][tab][tab][tab]xmlhttp[COLOR=#990000 ].[/color][b][COLOR=#000000 ]open[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"GET"[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]"?action=getEquipment&room="[/color] [COLOR=#990000 ]+[/color] [b][COLOR=#000000 ]encodeURIComponent[/color][/b][COLOR=#990000 ]([/color]val[COLOR=#990000 ]),[/color] true[COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab]xmlhttp[COLOR=#990000 ].[/color][b][COLOR=#000000 ]setRequestHeader[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"Content-type"[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]"application/x-www-form-urlencoded"[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab]xmlhttp[COLOR=#990000 ].[/color][b][COLOR=#000000 ]send[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab]window[COLOR=#990000 ].[/color]onload [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][b][COLOR=#000000 ]populate_dropdwn2[/color][/b][COLOR=#990000 ]([/color]document[COLOR=#990000 ].[/color][b][COLOR=#000000 ]getElementById[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'room'[/color][COLOR=#990000 ]));[/color]
[tab][tab][tab][COLOR=#FF0000 ]}[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#990000 ]</[/color]script[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]</[/color]head[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]body[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]form method[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"post"[/color] action[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]""[/color] name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"form"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][COLOR=#990000 ]<[/color]table border[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"0"[/color] cellspacing[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"0"[/color] cellpadding[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"0"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]<[/color]tr[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]td width[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"15%"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab]Room
[tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]td width[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"30%"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]select name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"room"[/color] id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"room"[/color] [b][COLOR=#0000FF ]class[/color][/b][COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"parent"[/color] onchange[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"populate_dropdwn2(this);"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]option value[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]""[/color] selected[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"selected"[/color][COLOR=#990000 ]>--[/color]Select Room[COLOR=#990000 ]--</[/color]option[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<?php[/color]  [b][COLOR=#0000FF ]while[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$rows[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_fetch_assoc[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color][COLOR=#990000 ])):[/color] [COLOR=#990000 ]?>[/color]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]option value[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"<?php echo $rows['room'];?>"[/color][COLOR=#990000 ]><?php[/color] [b][COLOR=#0000FF ]echo[/color][/b] [b][COLOR=#000000 ]htmlspecialchars[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$rows[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'room'[/color][COLOR=#990000 ]]);[/color] [COLOR=#990000 ]?></[/color]option[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<?php[/color] [b][COLOR=#0000FF ]endwhile[/color][/b][COLOR=#990000 ];[/color] [COLOR=#990000 ]?>[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]select[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]</[/color]tr[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]<[/color]tr[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]br[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]</[/color]tr[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]<[/color]tr style[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]""[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab]Asset Number
[tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]select name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"asset_no"[/color] [b][COLOR=#0000FF ]class[/color][/b][COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"child"[/color] id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"asset_no"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][tab][COLOR=#990000 ]<[/color]option value[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]""[/color] selected[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"selected"[/color][COLOR=#990000 ]>--[/color]Select Asset[COLOR=#990000 ]--</[/color]option[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]select[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][tab][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]</[/color]tr[COLOR=#990000 ]>[/color]
[tab][tab][tab][tab]
[tab][tab][tab]
[tab][tab][tab][COLOR=#990000 ]</[/color]table[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]</[/color]form[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]div id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"debug"[/color][COLOR=#990000 ]></[/color]div[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]</[/color]body[COLOR=#990000 ]>[/color]
[COLOR=#990000 ]</[/color]html[COLOR=#990000 ]>[/color]
 
by the way, I am not remotely advocating my code over Phil's. I have contributed to this thread purely to provide you and other readers with an alternative codeset that might, by comparison or otherwise, help the reader understand how to implement an ajax based client-server interaction.
it goes without saying that Phil has much more javascript experience than me and will certainly steer you to a better end solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top