2014-09-26 5 views
1
<select name="betrag" id="guitatype" onchange="test();"> 
    <?PHP    
     foreach($pscBetraege as $pscs) { 
      echo'<option value="'.$pscs.'">'.$pscs.'</option>'; 
     }    
    ?> 

<script type="text/javascript"> 
     function test(){ 
      if (document.getElementById("guitatype").value = "Paypal";) { 
      window.location.replace("http://stackoverflow.com"); 
     } 
    } 
     </script> 
</select> 

select id = "guitatype"값이 "PayPal"로 변경되면 사이트가 사용자를 ex : stackoverflow.com으로 리디렉션하지만 그 스크립트는 ' 일하지 마라.PHP 자바 스크립트 - 셀렉트가 변경되었을 때 리디렉션

Print .png here

+1

닫기 선택 태그 – mithunsatheesh

+0

값을 확인하는 곳은 == 아닙니다 =입니다. –

+0

@ coderboi_89 주석에 코드를 덤프하지 마십시오. –

답변

2

당신은 당신의 선택 태그를 닫아야합니다, 당신은 당신의 자바 스크립트의 일부 구문 오류가 있습니다.

<select name="betrag" id="guitatype" onchange="test(this.value);"> 
<?php   
foreach($pscBetraege as $pscs) { 
echo'<option value="'.$pscs.'">'.$pscs.'</option>'; 
}    
?> 
</select> 


<script type="text/javascript"> 
function test(val){ 
    if (val == "Paypal") { 
     window.location.replace("http://stackoverflow.com"); 
    } 
} 
0

당신이 누락가

=

변경 코드의 insted == : 또한,에서 getElementById를 가진 요소를 다시 선택 할 필요가없고, 단순히 함수로 값을 전달

if (document.getElementById("guitatype").value == "Paypal";) { window.location.replace("http://stackoverflow.com"); } 
관련 문제