안녕하세요 다중셀렉트 관련 질문 드립니다
본문
안녕하세요 다중셀렉트 관련 질문 드립니다
상품입력 내용중 다중으로 입력하는 폼을 구현해 보았습니다.
상기 이미지처럼 구현을 했는대
여기서 드리고 싶은 질문은
1차 선택시 저장을 하면 서울시, 부산시 이런식으로 잘저장이 됩니다
<select name="it_city1" id="it_city1" onchange="categorychange(this.form)">
<option value="0">--도시선택--</option>
<option value="서울시"<?php echo get_selected($it['it_city1'],"서울시"); ?>>서울시</option>
<option value="부산시"<?php echo get_selected($it['it_city1'],"부산시"); ?>>부산시</option>
</select>
1차 에서 2차 선택시 입력값은 넘어 오는대 상기 이미지 처럼 최초 --선택-- 으로 다시 돌아갑니다
<select name="it_city2" id="it_city2">
<option value="it_city2"<?php echo get_selected($it['it_city2'],"it_city2"); ?>>--선택--</option>
</select>
2차 선택도 입력값이 저장값으로 고정될수 있도록 하고 싶은대
고수님들의 조언 부탁들립니다
감사합니다
전체소스는 아래와 같습니다.
<script>
var tempX = 0;
var tempY = 0;
function imageview(id, w, h)
{
menu(id);
var el_id = document.getElementById(id);
//submenu = eval(name+".style");
submenu = el_id.style;
submenu.left = tempX - ( w + 11 );
submenu.top = tempY - ( h / 2 );
selectBoxVisible();
if (el_id.style.display != 'none')
selectBoxHidden(id);
}
</script>
<script language="javascript">
window.onload = function() {
document.getElementById("it_city1").onchange = function() { getClass(this.form.it_city1.options.selectedIndex) };
}
var classG = new Array(new Array("##선택##"), new Array("호텔관광ㄴㄴㄴㄴㄴ학부", "호텔ㅇㅇㅇ경영학부", "ㅇㅇㅇ외국어학부"),
new Array("프로그램학부", "영상학부", "디자인학부", "게임학부"),
new Array("헤어디자인학부", "피부미용학부"),
new Array("언론방송학과", "연기학부", "패션모델디자인학부"));
var temp, i=0, j=0;
var cselect;
function getClass(item) {
temp = document.getElementById("it_city2");
subCnt = temp.options.length;
for (i=(subCnt-1); i>0; i--) { temp.options[i] = null }
for (var j=0; j<classG[item].length; j++) {
cselect = classG[item][j];
temp.options[j] = new Option(cselect, cselect)
}
}
</script>
<form name="it_city1">
<div class="div1">
<select name="it_city1" id="it_city1" onchange="categorychange(this.form)">
<option value="0">--도시선택--</option>
<option value="서울시"<?php echo get_selected($it['it_city1'],"서울시"); ?>>서울시</option>
<option value="부산시"<?php echo get_selected($it['it_city1'],"부산시"); ?>>부산시</option>
</select>
</div>
<div>
<select name="it_city2" id="it_city2">
<option value="it_city2"<?php echo get_selected($it['it_city2'],"it_city2"); ?>>--선택--</option>
</select>
</div>
</form>
</td>
<td class="td_grpset">
<input type="checkbox" name="chk_ca_it_city1" value="1" id="chk_ca_it_city1">
<label for="chk_ca_it_re1">분류적용</label>
<input type="checkbox" name="chk_all_it_city1" value="1" id="chk_all_it_city1">
<label for="chk_all_it_re1">전체적용</label>
</td>
</tr>
답변 1
getClass( $( '#it_city1').prop( 'selectedIndex' ) );
$( '#it_city2' ).val( '<?php echo $it['it_city2'] ?>' ).prop( 'selected', true );