All pastes #215071 Raw Edit

Sans nom

public text v1 · immutable
#215071 ·published 2006-10-22 11:08 UTC
rendered paste body
<html>
<head>
<title>Double Linked comboboxes with php-mysql</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">

var store = new Array();
//store[0] = new Array('foo', '1');
store[1] = new Array(<?php echo return_array_JS_taches(); ?>);
store[2] = new Array(<?php echo return_array_JS_agences(); ?>);
store[3] = new Array(<?php echo return_array_JS_particuliers(); ?>);
store[4] = new Array(<?php echo return_array_js_prospects(); ?>);
store[5] = new Array(<?php echo return_array_JS_users(); ?>);
store[6] = new Array(<?php echo return_array_JS_fournisseurs(); ?>);


function init(formul, firBox, secBox) {
  optionTest = true;
  lgth = formul.secBox.options.length;
  formul.secBox.options[lgth] = null;
  if (formul.secBox.options[lgth]) optionTest = false;
}

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



</script>
</head>

<body onLoad="init('type_dest', 'first', 'second')">

<?php
$req = 'SELECT id_type_rdv, libelle';
$req .= ' FROM types_rdv';
$req .= ' ORDER BY libelle ASC';

$i = 0;
connec();
$exe = mysql_query($req) or die($req);
mysql_close();

$first_box = '<select name="first" onChange="populate(this.form, \'first\', \'second\')">'."\n";
$first_box .= '<option>Choix d\'un destinataire</option>'."\n";
while($res = mysql_fetch_assoc($exe)) {
  $first_box .= '<option value="'.$res['id_type_rdv'].'">'.$res['libelle'].'</option>'."\n";
}
$first_box .= '</select>';

?>
<form name="type_dest">
<?php echo $first_box; ?>

<select name="second"></select>
</form>