javascript - Change the url and reload on change of dropdown value which is in common header -
i new yii , want change url , reload current view page on change of dropdown value in admin's common header field. dropdown
echo $form->dropdownlist($siteid, 'selectedsiteid', $data,$htmloptions, array('class' => "form-control"));
the current urls may following
1. http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewtags/sid/6
2. http://localhost/zyntegra_commoditylifev2/admin/category/viewcategory/sid/ 3.http://localhost/zyntegra_commoditylifev2/admin/site/index
suppose current changed dropdown value 10
, if current url (1) 1 need change url this
http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewtags/sid/10
if current url (2) 1
http://localhost/zyntegra_commoditylifev2/admin/category/viewcategory/sid/10
, if it's (3) 1 there no need of reload.
plz me solve problem.
thanks in advance
try like,
var tagsurl='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewtags/sid/'; var caturl='http://localhost/zyntegra_commoditylifev2/admin/category/viewcategory/sid/'; $(function(){ $('#your-select-id').on('change',function(){ href=window.location.href; if(href.indexof('viewtags') !== -1){ window.location.href=tagsurl+this.value;//append value of select element } else if(href.indexof('viewcategory') !== -1){ window.location.href=caturl+this.value;//append value of select element } }); });
above code may complete task.
updated, sid try like,
// use location.href in url current url var url='http://localhost/zyntegra_commoditylifev2/admin/sitetag/viewtags/sid/110'; alert(url.split('sid/')[1]);//110
updating @salini answer like,
function reloadpage() { var sid = $( '#site_selectedsiteid' ).val( ); var currenturl = window.location.pathname; var n=currenturl.indexof("/sid");// use '/sid' in indexof remove else part if(n!=-1) { var newurl = currenturl.substring(0,n); window.location.href = newurl + '/sid/' + sid; } }
Comments
Post a Comment