Jump to content


Photo

dynamic drop down


  • Please log in to reply
3 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 09 August 2006 - 08:57 PM

hey guys,

I have 2 drop downs, my first one is being populated by an array but I'd like to have my 2nd one populated from a db depending on the value of the first drop down.

I already know how to do it but my way requires the form to be refreshed... would there be a simple way to do is without having to reload the page?



#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 09 August 2006 - 10:53 PM

anyone??? been trying to do this for a while without any success....

#3 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 11:01 PM

Without a page refresh, you need javascript.
Make a donation to phpfreaks. They need your help![br][br]

#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 09 August 2006 - 11:14 PM

I know and I tried different solutions but without any success....

here's what I have so far
echo '<SCRIPT language=JavaScript type=text/javascript> ';
echo 'var store = new Array();';
for ($i=0; $i<$numRows; $i++){ //for each item
	$js_array = "";
	$sql = 'SELECT * FROM clubnights';	
	
	$result = mysql_query($sql) or die (mysql_errno().": select ".mysql_error()."<BR>" . $sql);		
	while ($row = mysql_fetch_array($result)) { 
		$js_array .= "'" . $row['club'] . "','" . $row['club'] . "',";			 		
	}
	$js_array = rtrim( $js_array , ","); // trim final comma
	echo 'store['.$i.'] = new Array('; // start javascript array
	echo $js_array . "); ";
} // end for 
echo '</SCRIPT>';
<SCRIPT language=JavaScript type=text/javascript>
<!-- Begin

/* Execute init() function */
window.onload = initialize;
function initialize () {
	if (self.init) self.init();
}

function init()
{
	optionTest = true;
	lgth = document.forms[0].night.options.length - 1;
	document.forms[0].night.options[lgth] = null;
	if (document.forms[0].night.options[lgth]) optionTest = false;
	if (optionTest) self.populate();
}

function populate()
{
	if (!optionTest) return;
	var box = document.forms[0].club;
	var number = box.options[box.selectedIndex].value;
	if (!number) return;
	var list = store[number];
	var box2 = document.forms[0].night;
	box2.options.length = 0;
	for(i=0;i<list.length;i+=2)
	{
		box2.options[i/2] = new Option(list[i],list[i+1]);
	}

where "night" is m first drop down and "club" is my second.

night is populated by an array and I want "club" to be populated depending on what night is chosen

my table clubnights looks like this

id  | night      | club  |.....
1  | Friday     | Aria   |
2  | Thursday | Circus |
..... etc

so a night can have several clubs

I'm really lost




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users