새 창에서 열기에 대한 질문을 올렸지 만 window.location을 사용하면 작동하지 않습니다 ?? 내 자바 스크립트에 문제가 있습니까?선택 상자 문제 - 첫 번째 선택에 기초한 두 번째 옵션
<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>
그것의 내가 아는 좀 지저분 ...
<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>
는 내가 원하는이 어쨌든 행복하지 않다 정직 두 번째 선택 상자가 될 때까지 버튼을 제출 숨길 수있는 방법 선택한 ...하지만 난 자바 전문가! 누구든지 올바른 방향으로 나를 가리킬 수 있습니까?
도움을 주셔서 대단히 감사합니다. Andy, 나는 작동하도록 할 수 없습니다 ... 실제로 아무 것도하지 않습니까? 만약 submit을 누르면 그냥 폼이 다시로드됩니다. (첫번째 선택 옵션 하나만 시도하고 있습니다) –
@Charles Marsh :'onsubmit' 이벤트가 끝날 때'return false;를 추가하여 페이지가 다시로드되는 것을 멈추게하십시오. . –