채택완료

select문의 option값을 가져오는 방법에 대한 문의 입니다.

2016-01-27 (수) 09:14:59 3,904
Copy
function checkPrice(wr_id){    var select = document.getElementById("if_day").value;    var use = document.getElementById("use[" + wr_id + "]").value;    var stay = document.getElementById("if_stay[" + wr_id + "]").value;    var person = document.getElementById("if_person[" + wr_id + "]").value;    if(use)    {        window.alert("선택하신 객실은 예약이 불가능합니다.");        return false;    }    $.ajax({            url: g5_bbs_skin_url + "/check.ajax.php",            data: {"bo_table": g5_bo_table, "wr_id": wr_id, "select": select, "stay" : stay, "person" : person},             error:function(request,status,error){                window.alert("프로그램 오류가 발생하였습니다.");            },            success:function(data){                document.getElementById("price[" + wr_id + "]").innerHTML = data;                checkTotal();            }    })    return;}<form id="mara_write" name="fwrite" method="post" action="<?php echo G5_BBS_URL; ?>/write_update.php" enctype="multipart/form-data" onsubmit="return checkWrite(this);" style="width:<?php echo $width; ?>;">    <p>        <input type="hidden" name="w" value="<?php echo $w; ?>">  <input type="hidden" name="roomval">  <input type="hidden" name="wr_subject" value="tmp_text">        <input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">        <input type="hidden" name="roomvar">    </p>    <h2 class="guide"><span></span>이용안내</h2>    <ol class="explain">        <li>인터넷예약이 가능한 기간은 <strong><?php echo $date['min']; ?>부터 <?php echo $date['max']; ?>까지</strong>이며, 그 외의 기간은 전화로 문의해주세요.</li>        <li>1회 예약시 숙박이 가능한 기간은 <strong>최대 <?php echo $board['bo_5']; ?>박 <?php echo $board['bo_5'] + 1; ?>일</strong>이며, 그 이상의 기간은 전화로 문의해주세요.</li>        <li>선택한 숙박일자에 이용할 수 없는 객실은 선택할 수 없거나 숙박기간이 조정되어 보여질 수 있습니다.</li>        <li>예약신청이 완료된 후 <strong><?php echo $board['bo_6']; ?>일 이내에 입금</strong>이 확인되지 않으면 별도의 확인절차없이 예약은 취소됩니다.</li>        <li>무통장입금 계좌번호안내 : <?php echo $board['bo_10']; ?></li>    </ol>    <h2 class="rm_select"><span></span>객실선택</h2>    <p class="select">        <span class="sound_only">날짜를 변경하시면 입력한 내용이 초기화 됩니다.</span>        <label for="if_day" class="sound_only">날짜</label>        <select name="select" id="if_day" class="day_select"><?php echo optionDate($select); ?></select>    </p>    <table class="mara_rw">    <caption>객실 선택</caption>    <colgroup>        <col class="rm_grid_5"><!-- 25% -->        <col class="rm_grid_2"><!-- 10% -->        <col class="rm_grid_3"><!-- 15% -->        <col class="rm_grid_3"><!-- 15% -->        <col class="rm_grid_3"><!-- 15% -->        <col class="rm_grid_2"><!-- 10% -->        <col class="rm_grid_2"><!-- 10% -->    </colgroup>    <thead>    <tr>        <th scope="col">객실정보</th>        <th scope="col">기준/최대</th>        <th scope="col">숙박일자</th>        <th scope="col">숙박기간</th>        <th scope="col">인원</th>        <th scope="col">이용금액</th>        <th scope="col">선택</th>    </tr>    </thead>    <tfoot>    <tr>        <td colspan="5">총 결제금액</td>        <td class="red" colspan="2"><span id="total">0</span>원</td>    </tr>    </tfoot>    <tbody>    <?php for($i = 0;$i < $max; $i++){ ?>    <tr>        <td class="left">                <input type="hidden" name="use[<?php echo $ROOM[$i]['wr_id']; ?>]" id="use[<?php echo $ROOM[$i]['wr_id']; ?>]"  value="<?php echo $ROOM[$i]['disabled']; ?>">            <a href="#none" onclick="window.open('<?php echo $ROOM[$i]['link']; ?>');"><img src="<?php echo $board_skin_url; ?>/img/b_room.gif" alt="상세정보"></a>            <span id="gname[<?php echo $ROOM[$i]['wr_id']; ?>]">[<?php if($ROOM[$i]['ca_name']){ echo $ROOM[$i]['ca_name'] . '/'; } ?><?php echo $ROOM[$i]['wr_1']; ?>평형] <?php echo $ROOM[$i]['wr_subject']; ?></span>        </td>        <td><?php echo $ROOM[$i]['wr_2']; ?>명/<?php echo $ROOM[$i]['wr_3']; ?>명</td>        <td><?php echo $select; ?><input type="hidden" name="wr_1" value="<?php echo $select;?>"></td>        <td>            <label for="if_stay[<?php echo $ROOM[$i]['wr_id']; ?>]" class="sound_only">숙박기간</label>            <select name="stay[<?php echo $ROOM[$i]['wr_id']; ?>]" id="if_stay[<?php echo $ROOM[$i]['wr_id']; ?>]" onchange="checkPrice('<?php echo $ROOM[$i]['wr_id']; ?>');" <?php echo $ROOM[$i]['disabled']; ?>>                <?php optionStay($ROOM[$i]['stay']); ?>            </select>            <input type="text" class="frm_input" size="10" id="흑흑" name="optionValue">        </td>        <td>            <label for="if_person[<?php echo $ROOM[$i]['wr_id']; ?>]" class="sound_only">인원선택</label>            <select name="person[<?php echo $ROOM[$i]['wr_id']; ?>]" id="if_person[<?php echo $ROOM[$i]['wr_id']; ?>]" onchange="checkPrice('<?php echo $ROOM[$i]['wr_id']; ?>');" <?php echo $ROOM[$i]['disabled']; ?>>                <?php optionPerson($ROOM[$i]['wr_2'], $ROOM[$i]['wr_3']); ?>            </select>        </td>        <td><span id="price[<?php echo $ROOM[$i]['wr_id']; ?>]"><?php echo number_format($ROOM[$i]['price']); ?></span>원</td>        <td>            <?php if(isset($ROOM[$i]['inquiry']) == true){ ?>            <a href="<?php echo $ROOM[$i]['inquiry']; ?>"><img src="<?php echo $board_skin_url; ?>/img/b_inquiry.gif" alt="예약확인"></a>            <?php } else{ ?>            <input type="checkbox" name="room[]" value="<?php echo $ROOM[$i]['wr_id']; ?>"  onclick="checkTotal();" <?php echo $ROOM[$i]['disabled']; ?>>            <?php } ?>        </td>    </tr>    <?php } ?>    </tbody>    </table></form>

위의 소스중

<select name="stay[<?php echo $ROOM[$i]['wr_id']; ?>]" id="if_stay[<?php echo $ROOM[$i]['wr_id']; ?>]" onchange="checkPrice('<?php echo $ROOM[$i]['wr_id']; ?>');" <?php echo $ROOM[$i]['disabled']; ?>>
                <?php optionStay($ROOM[$i]['stay']); ?>
            </select>
            <input type="text" class="frm_input" size="10" id="흑흑" name="optionValue">

name="stay[~ 에서 사용되는 Select의 option값을 뽑아오고자 합니다.

구글링을 통해 이런 저런 시도를 했지만...

스크립트 언어는 어렵네여 ㅠ

조언 좀 부탁드립니다. 흑흑 

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트
2016-01-27 (수) 09:47:06
Copy
$(function() {   $("select[name^='stay[']").on("change", function() {      alert("선택하신 selectbox의 값은" + $(this).val() + "입니다.");   });});

저렇게 php로 같이 되어 있는 것보단 html로 렌더링이 된 페이지를 보는 게 제일 좋습니다.

저런 식으로 하시면 되지 않을까 싶네요. 

답변에 대한 댓글 1개

제이쿼리로 alert 방법이네요. 감사합니다.

답변을 작성하려면 로그인이 필요합니다.