Redirect issue in select element

江枫思渺然 提交于 2020-01-25 08:34:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!