brooksh Posted January 15, 2009 Share Posted January 15, 2009 I already have a javascript that will populate a drop down with a refresh. I would like to be able to do this, without refreshing the page. Any help would be appreciated. <SCRIPT language=JavaScript> function reload(form) { var val=form.make.options[form.make.options.selectedIndex].value; self.location='index.php?make=' + val ; } </script> <? @$make=$_GET['make']; // Use this line or below line if register_global is off $quer2=mysql_query("SELECT DISTINCT make FROM car_database order by make"); $quer=mysql_query("SELECT DISTINCT model FROM car_database where make='$make' order by model"); ?> Make: <select name='make' onchange="reload(this.form)" ><option value="">Select one</option> <? while($noticia2 = mysql_fetch_array($quer2)) { echo "<option value='$noticia2[make]'"; if($noticia2['make']==@$make){echo "selected";} echo ">$noticia2[make]</option>"; } ?> </select> <BR>Model: <select name="model" onchange="ShowTB(this,'model2');"><option value="">Select one</option> <? while($noticia = mysql_fetch_array($quer)) { ?> <option value='<?=$noticia[model]?>' <? if($model == "$noticia[model]"){ echo "selected"; } ?>><?=$noticia[model]?></option> Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 15, 2009 Share Posted January 15, 2009 Well, this has been moved into the AJAX forum. But, depending on the amount of data it might be more efficient to just handle it in JavaScript. If you are dealing with a "relatively" small list of data, you could simply use the data in the database to create javascript arrays on the page for all of the select list options and swap out the values only using JavaScipt. I say relatively because how big is too big is up to you. You could run some tests to see if there are any performance issues, but you could probably have hundreds of options before you see anything noticable. If you do have a lot of options or just don't want all the options in the code, then you would want to use AJAX. however, you should include a way for users without JS to use the form too. Probably just keep the currentl functinoality you have, but instead of using javascript to change the page have a button to update the list that simple submits the form and checks the "make" field to redisplay the form with the appropriate values. So, if you do want to use AJAX, here is a tutorial for you: http://www.satya-weblog.com/2007/04/dynamically-populate-select-list-by.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.