2013-08-26 5 views
0

간단한 HTML 드롭 다운 선택 상자가 있습니다.HTML 드롭 다운 리디렉션 선택

'일단 무언가가 선택되면'이 기능을 사용자 지정 URL로 리디렉션합니다.

다음은 나의 마크 업입니다.

<fieldset id="size"><legend>Product Options</legend> 
<div class="wpsc_variation_forms"> 
<table> 
<tr><td class="col1"><label for="variation_select_48_5">Choose Size:</label></td> 
<td class="col2"><select class="wpsc_select_variation" name="variation[5]" id="variation_select_48_5"> 
<option value="0" >-- Please Select --</option> 
<option value="8" >Large</option> 
<option value="7" >Medium</option> 
<option value="6" >Small</option> 
</select></td></tr> 
</table> 
</div><!--close wpsc_variation_forms--> 
</fieldset> 

나는 비슷한 질문을 발견했다. 하지만 주어진 해결책은 다소 어색해 보인다. jQuery로

SELECT Dropdown that redirects without Javascript

+0

맞춤 URL의 출처는 어디입니까? – Rooster

답변

2

:

$(function() { 
    $('#variation_select_48_5').change(function() { 
     document.location = 'http://customurl.abc'; 
    }); 
}); 
0

난의 요소를 선택하는 onchange 이벤트를 할당 및 URL로 옵션 '값을 알고있는 가장 쉬운 방법.

<select onchange="window.location = this.options[this.selectedIndex].value;"> 
<option value="http://your-url">Large</option> 
</select> 
0

희망이

$("select#wpsc_select_variation").change(function(){ 
    if ($(this).val() !== 0) { 
     switch($(this).val()) 
     { 
      case(8): 
       window.location.href = http://www.8.com 
      case(7): 
       window.location.href = http://www.7.com 
      case(6): 
       window.location.href = http://www.6.com 
     } 
    } 
}); 
0

가 나는 기능 litte 작성하고 다음 재곡 결과에 따라 그 발생하게하는 데 도움이 필요한 경우에만 자바 스크립트는 내

<?PHP 
    function redirect($where){  
     header("Location: $where"); 
    } 

    if ($_REQUEST['select1'] == '8'){ 
     redirect('http://example.com/somewhere.php'); 
    }elseif($_REQUEST['select1'] == '7'){ 
     redirect('http://example.com/elsewhere.php'); 
    }elseif($_REQUEST['select1'] == '6'){ 
     redirect('http://example.com/elsewhere.php'); 
    } 
?> 

<form> 
<select name="select1" class="wpsc_select_variation" name="variation[5]" id="variation_select_48_5" onchange="this.form.submit()"> 
<option value="0" >-- Please Select --</option> 
<option value="8" >Large</option> 
<option value="7" >Medium</option> 
<option value="6" >Small</option> 
</select> 

select 제출을 트리거 할 태그 onchange="this.form.submit()"