ciao, chi mi aiuta a popolare sta select?![]()
codice:<script language="JavaScript"> var arItems = new Array() arItems = [ <? $cmd = "SELECT db_sw_id, db_version_id, version FROM db_version"; $rs = mysql_query($cmd); while($aItems = mysql_fetch_array($rs)){ echo "[".$aItems['db_sw_id']."," .$aItems['db_version_id'].",'".$aItems['version']."']"; } ?> ] </script> <script> function fillItems( intStart ) { var fTypes = document.form1.db_sw var fItems = document.form1.db_version var a = arItems var b, c, d, intItem, intType if ( intStart > 0 ) { for ( b = 0; b < a.length; b++ ) { if ( a[b][1] == intStart ) { intType = a[b][0]; } } for ( c = 0; c < fTypes.length; c++ ) { if ( fTypes.options[ c ].value == intType ) { fTypes.selectedIndex = c; } } } if ( intType == null ) { intType = fTypes.options[ fTypes.selectedIndex ].value } fItems.options.length = 0; for ( d = 0; d < a.length; d++ ) { if ( a[d][0] == intType ) { fItems.options[ fItems.options.length ] = new Option( a[d][2], a[d][1] ); // no line-break here } if ( a[d][1] == intStart ) { fItems.selectedIndex = fItems.options.length - 1; } } } </script>
a questo punto basterebbe richiamare la funzione all'onchange..
ma non riesco a farlo funzionare.. qualcuno capisce il perché?codice:<td> <SELECT name="db_sw" id="db_sw" onChange="fillItems(0);"> <option value="">select a sw type...</option> <? $type_list = GetListing("db_sw", "db_sw_id, db_sw_name"); foreach($type_list as $k => $v ) { echo "<option value=\"$k\">$v</option>\n"; } ?> </SELECT> </td> <td> <SELECT name="db_version" id="db_version"> </SELECT>
casomai il tutorial é qui:
http://www.devarticles.com/c/a/Java...us-Client-Side/
ps: getListing non fa altro che scrivere le option della prima select....

Rispondi quotando