2017-09-27 6 views
0

사용자가 누를 때마다 새 드롭 다운 목록이 작성되고 선택한 값이 표시되지 않도록 추가 단추를 작성해야합니다. 새로운 dpl에서. 또한 첫 번째 드롭 다운 목록은 데이터베이스에서 데이터를 가져 오는 것입니다 (이것이 완료되었습니다).새 드롭 다운 목록을 만들고 새 dpl에서 선택한 값을 제거하는 버튼을 추가하십시오.

[예제] [1]을 시도했지만 작동하지 않습니다! 어떤 팁? 이 exacly 무엇을 경우

또한,이 검증 등 등

HTML 코드

<div id="services-D" class="oneField" >     
        <label id="services-L" for="services" class="label preField reqMark" style="width: 100px; min-width:0">Services</label><br> 
        <select id="c_service" name="c_service" class="required dynamic-select" style="width:170px" > 
         <option value="">Select Service...</option> 
         <?php 
          $res=mysqli_query($dbc,"Select t1 t2 Where t4s = 'Y'"); 
          while ($row = mysqli_fetch_array($res)) { ?> 
          <option value = <?php echo $row['invoice_code']?> > <?php echo $row['t1'] . ": " . $row['t2'];}?> </option> 
         ?> 
        </select> 

       </div> 
<button type="button" id="btn_add_service" style="">Add Service</button> 

에 대한 그래서 필요가 연습 jQuery를

<script> 
$('#btn_add_service').on('click', function() { 
    selected = $('#c_service').prop('selectedIndex'); 
    if (selected != 0 && $('#c_service').find('option').length != 2){ 
    newselector = $('<select id="c_service"></select>').insertAfter('#c_service'); 
    $('#c_service').find('option').each(function(index,item) { 
     if (index != selected){ 
     $(newselector).append(item); 
     } 
    }); 
    } 
}); 
</script> 
+0

무엇'선택 값 '? 일부 HTML, JavaScript를 공유하여 문제를 예시하십시오. –

+0

지금 확인하십시오 @AlanLarimer – noel293

답변

1

확실하지 않습니다 당신은 찾고 있습니다, 그러나 나는 당신의 묘사에 기초하여 그것을 만들려고 노력했습니다. 희망은 this link 당신을 도울 수있다.

HTML :

<select onchange="NewSelection(this);"> 
    <option>Select an option</option> 
    <option>Option 1</option> 
    <option>Option 2</option> 
    <option>Option 3</option> 
    <option>Option 4</option> 
    <option>Option 5</option> 
</select> 

자바 스크립트/JQuery와 :

function NewSelection(selector){ 
    selected = $(selector).prop('selectedIndex'); 
    if (selected != 0 && $(selector).find('option').length != 2){ 
    newselector = $('<select onchange="NewSelection(this);"></select>').insertAfter(selector); 
    $(selector).find('option').each(function(index,item) { 
     if (index != selected){ 
     $(newselector).append(item); 
     } 
    }); 
    } 
} 
+0

고마워요! 이 하나는 잘 작동합니다! 나는 그것을 수정해야만하므로 다른 하나를 인쇄 할 것이다 !!! – noel293

+0

실제로이 코드가있는 버튼을 사용하면 약간 복잡해집니다! 그것은 새로운 dpl리스트를 보여 주지만 한 번만 보시면 저의 질문을 편집 할 수 있습니다. – noel293