I have a simple HTML drop-down select box.
I would like this to function as 'once something is selected' > the page then redirects to a custom URL.
Below is my mark-up.
<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>
I found a similar question; but the solution given seems a bit clunky.
SELECT Dropdown that redirects without Javascript
I have a simple HTML drop-down select box.
I would like this to function as 'once something is selected' > the page then redirects to a custom URL.
Below is my mark-up.
<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>
I found a similar question; but the solution given seems a bit clunky.
SELECT Dropdown that redirects without Javascript
Share Improve this question edited May 23, 2017 at 12:21 CommunityBot 11 silver badge asked Aug 26, 2013 at 21:26 Lieutenant DanLieutenant Dan 8,29828 gold badges97 silver badges216 bronze badges 1- where does the custom url e from? – Rooster Commented Aug 26, 2013 at 21:30
4 Answers
Reset to default 3With jQuery:
$(function() {
$('#variation_select_48_5').change(function() {
document.location = 'http://customurl.abc';
});
});
The easiest way i know of is assigning an onchange
event to select element and making options' values as urls.
<select onchange="window.location = this.options[this.selectedIndex].value;">
<option value="http://your-url">Large</option>
</select>
I would write i litte function and then trigger it depending on the retuned result
<?PHP
function redirect($where){
header("Location: $where");
}
if ($_REQUEST['select1'] == '8'){
redirect('http://example./somewhere.php');
}elseif($_REQUEST['select1'] == '7'){
redirect('http://example./elsewhere.php');
}elseif($_REQUEST['select1'] == '6'){
redirect('http://example./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>
the only javascript required is within the select
tag to trigger the submit onchange="this.form.submit()"
Hope this helps
$("select#wpsc_select_variation").change(function(){
if ($(this).val() !== 0) {
switch($(this).val())
{
case(8):
window.location.href = http://www.8.
case(7):
window.location.href = http://www.7.
case(6):
window.location.href = http://www.6.
}
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745664974a4639067.html
评论列表(0条)