이 경우에 수정하기 에서 value 값을 데이터에서 가져와서 표시하려면 어떻게 해야 하나요?
주소 셀렉트를 자료실에서 가져와서 썼는데 해당 코드에서 어떻게 해야 수정하기를 할 때 이전에 등록한 데이터를 표시해 주는지 모르겠습니다. 어떻게 해야 하나요?
배열이 너무 많아서 일일히 select 에 입력하지는 못하는데 ㅠㅠ
<tr>
<th> <label class="control-label" for="sido">시/구/군<span style="color: #ef0000;">*</span><strong class="sound_only">필수</strong></label>
</th>
<td>
<div class="input-group">
<select class="required box_style mgb" name="sido" id="sido" style="height: 50px;"></select>
<span style="margin-right: 10px;"></span>
<select class="required box_style" name="gugun" id="gugun" style=" height: 50px;"></select>
</div>
</td>
</tr>
<tr>
<th> <label class="control-label" for="dong">동/번지<span style="color: #ef0000;">*</span><strong class="sound_only">필수</strong></label>
</th>
<td>
<div class="input-group">
<select class="required box_style mgb" name="dong" id="dong" style=" height: 50px;"></select>
<span style="margin-right: 10px;"></span>
<input type="text" name="bunji" value="<?php echo $write['bunji'] ?>" id="bunji" required class="form-control input-sm box_style" style=" height: 50px;">
</div>
</td>
</tr>
<script>
function sojaeji(sido, gugun, dong) {
var
addr ={
'시도' : ['서울','부산','대구','인천','광주','대전','울산','강원','경기','경남','경북','전남','전북','제주','충남','충북'],
'서울' : ['강남구','강동구','강북구','강서구','관악구','광진구','구로구','금천구','노원구','도봉구','동대문구','동작구','마포구','서대문구','서초구','성동구','성북구','송파구','양천구','영등포구','용산구','은평구','종로구','중구','중랑구'],
'부산' : ['강서구','금정구','남구','동구','동래구','부산진구','북구','사상구','사하구','서구','수영구','연제구','영도구','중구','해운대구','기장군'],
'대구' : ['남구','달서구','동구','북구','서구','수성구','중구','달성군'],
'인천' : ['계양구','남구','남동구','동구','부평구','서구','연수구','중구','강화군','옹진군'],
'광주' : ['광산구','남구','동구','북구','서구'],
'대전' : ['대덕구','동구','서구','유성구','중구'],
'울산' : ['남구','동구','북구','중구','울주군'],
};
this.sido = document.getElementById('sido');
this.gugun = document.getElementById('gugun');
this.dong = document.getElementById('dong');
var parent = this;
makeOption('시도', this.sido);
if (sido) this.sido.value = sido;
if (gugun) {
makeOption(sido, this.gugun);
this.gugun.value = gugun;
}
if (dong) {
makeOption(sido + '->' + gugun, this.dong);
this.dong.value = dong;
}
this.sido.onchange = function() {
makeOption(this.value, parent.gugun);
makeOption(this.value + '->' + parent.gugun.value, parent.dong);
};
this.gugun.onchange = function() {
makeOption(parent.sido.value + '->' + this.value, parent.dong);
};
function makeOption(idx, obj) {
var html = '', i=0;
for (; i<addr[idx].length; i++) html += '<option value="'+addr[idx][i]+'">'+addr[idx][i]+'</option>';
obj.innerHTML = html;
}
}
</script>
답변 3개
답변을 작성하려면 로그인이 필요합니다.