2014-01-07 6 views
0

데이터베이스의 스크립트를 사용하여 선택 옵션 양식을 채 웁니다. 지금 내가 뭘하고 싶은지 사용자가 옵션을 변경하면 일치하는 1을 선택한 다음 다른 하나의 PHP 파일에서 div 1을 입력하여 세부 정보를 채우는 스크립트를 실행합니다. 스크립트로 선택 옵션을 채우지 않으면 잘 실행됩니다. 비록 내가 스크립트를 사용하고 있지만 옵션은 올바르게 존재하지만 변경시에는 아무 일도 일어나지 않습니다. 헤더다른 스크립트에서 채워지는 변경 선택 옵션의 JS

function populateSelect(){ 
    var load = $.get('popRoundSel.php',{gameNo:"<?php echo $_POST['gameNo']; ?>"}); 
    $(".round").html('Refreshing'); 
    load.error(function() { 
     console.log("Mlkia kaneis"); 
     $(".round").html('failed to load'); 
     // do something here if request failed 
    }); 
    load.success(function(res) { 
     console.log("Success"); 
     $(".round").html('<select id="roundselect"><option>----</option>'+res+'</select>'); 
    }); 
    load.done(function() { 
     console.log("Completed"); 
    }); 
} 
$(document).ready(function() 
    { 
     $('#roundselect').change(function() 
     { 
      var selected = $(this).find(':selected').html(); 
      $.post('roundinfo_sc.php', {'beverage': selected}, function(data) { 
       $('#result').html(data); 
      }); 
     }); 
    }); 

페이지 코드

<h2>Select a round to see more details</h2> 
<div class="round"> 
<script> 
populateSelect(); 
</script> 
</div> 
<div id="result">  
</div> 
+0

() :

그래서 당신은이 같은 부하 succes에 기능 내부의 $('#roundselect').change(function()...을 넣어한다 > '+ res +' ' – LefterisL

답변

0

그럼 문제에

JS는 새를 추가 할 때 당신이 그것을 결합하는 모든 이벤트를 느슨하게 선택이다. ;`실행 내가`<선택 ID = "roundselect"와 사업부를 입력거야`populateSelect 번

load.success(function(res) { 
     console.log("Success"); 
     $(".round").html('<select id="roundselect"><option>----</option>'+res+'</select>'); 
    $('#roundselect').change(function() 
     { 
      var selected = $(this).find(':selected').html(); 
      $.post('roundinfo_sc.php', {'beverage': selected}, function(data) { 
       $('#result').html(data); 
      }); 
     }); 

}); 
+0

이제 고맙겠습니다. – LefterisL

+0

다행이었습니다. – cretzzzu3000

관련 문제