问题
I have used dependency drop downs.
<html>
<body>
<select id="parent-cat" name="parent-cat" onchange="getChildrenList(this.value)">
<option value ="">- Please Select -</option>
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test2</option>
</select>
<select id="child-cat" name="child-cat"
onchange="getChildUrl(this.value)">
<option value ="">- Product category -</option>
</select>
<script>
function getChildrenList(parentId) {
if(parentId !=''){
var customurl = "result.php";
jQuery.ajax({
url: customurl,
type: "POST",
data : 'category_id='+parentId,
dataType: 'json',
success : function(result) {
var optionHtml;
optionHtml +='<option value="">-Product Category-</option>';
for(var option of result){
optionHtml +='<option value="'+option.url+'">'+option.name+'</option>';
}
jQuery('#child-cat').html(optionHtml);
}
});
}
}
function getChildUrl(childUrl) {
var url = childUrl;
if (url) {
window.location = url; // redirect
}
return false;
}
</script>
</body>
</html>
I am appending the result into next drop down once first drop down is changed.
My issue is Once the second drop down is selected it is redirecting to the url, but the option is not selected.
I am looking for code how both the drop downs are selected once the url is redirected after changing the second dropdown.
Please anyone help me on this. Thanks
来源:https://stackoverflow.com/questions/54037550/redirect-issue-in-select-element