Answer the question
In order to leave comments, you need to log in
How to reload a page using JS?
Good day.
There is a store (on Django-Oscar, but not so important), on the product page there is a dropdown menu that lists all the options for this product (packaging, etc.). It is necessary for me that after an element choice in this dropdown, the page of this product returned.
================== UPD ==================
And you can do this so that the page remembers which element was chosen? That is, on the page with the product, the corresponding element in the dropdown was selected?
========================================
Here is how the dropdown list is formed:
for child in child_products:
summary = child.title
...
choices.append((child.id, summary))
self.fields['child_id'] = forms.ChoiceField(
choices=tuple(choices), label=_("Variant"),
widget=widgets.AdvancedSelect(disabled_values=disabled_values))
url(r'^(?P<product_slug>[\w-]*)_(?P<pk>\d+)/$',
self.detail_view.as_view(), name='detail')
Answer the question
In order to leave comments, you need to log in
<select id="dynamic-select">
<option value="http://www.google.com/">Google</option>
<option value="http://www.youtube.com/">YouTube</option>
<option value="http://www.yandex.ru/">Yandex</option>
</select>
<script>
$('#dynamic-select').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
}
return false;
});
</script>
<select id="dynamic-select">
<option id="s1" value="test.html?s=s1">Google</option>
<option id="s2" value="test2.html?s=s2">YouTube</option>
<option id="s3" value="test3.html?s=s3">Yandex</option>
</select>
<script>
$(document).ready(function () {
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
var selected = $.urlParam('s');
if (selected){
$("#dynamic-select option[id="+selected+"]").prop("selected", "selected");
}
$('#dynamic-select').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
}
return false;
});
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question