Je viens de poster une question à propos de l'ouverture dans une nouvelle fenêtre, mais si j'utilise window.location cela ne fonctionne pas ?? Y at-il un problème avec mon javascript?problème avec les boîtes de sélection - secondes options basées sur la première sélection
<script type="text/javascript">
function setOptions(chosen){
var selbox = document.formName.table;
selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length] = new Option('No diploma selected',' ');
}
if (chosen == "1") {
selbox.options[selbox.options.length] = new Option('first choice - option one','http://www.pitman-training.com');
selbox.options[selbox.options.length] = new Option('first choice - option two','onetwo');
}
if (chosen == "2") {
selbox.options[selbox.options.length] = new Option('second choice - option one','twoone');
selbox.options[selbox.options.length] = new Option('second choice - option two','twotwo');
selbox.options[selbox.options.length] = new Option('second choice - option three','twothree');
selbox.options[selbox.options.length] = new Option('second choice - option four','twofour');
}
if (chosen == "3") {
selbox.options[selbox.options.length] = new Option('third choice - option one','threeone');
selbox.options[selbox.options.length] = new Option('third choice - option two','threetwo');
}
}
</script>
Son un peu en désordre, je sais ...
<form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="optone" size="1" onchange="setOptions(document.formName.optone.options[document.formName.optone.selectedIndex].value);">
<option value=" " selected="selected">Please select a diploma</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
<select name="table" size="1" >
<option value=" " selected="selected">No diploma selected</option>
</select>
<input type="submit" onclick="ob=this.form.table;window.location(ob.options[ob.selectedIndex].value)"/>
</form>
pour être honnête, je ne suis pas content de ce que je veux quand même un moyen de cacher le bouton Soumettre jusqu'à ce que la seconde zone sélectionnée a été sélectionné ... mais je ne suis pas un expert Java! Est-ce que quelqu'un peut-il me montrer la bonne direction?
Merci beaucoup pour votre aide Andy, je ne peux pas le faire fonctionner ... il ne fait rien réellement? si je clique sur submit il recharge juste le formulaire ... (j'essaie seulement l'option premier choix) –
@Charles Marsh: Essayez d'ajouter 'return false;' à la fin de l'événement 'onsubmit' pour arrêter le rechargement de la page . –