jquery - Checkbox Selected Values Get in Browser URL using Javascript -


i need check box selected values in browser url execute query per selection base.

html code

  <div style="width:200px; float:left">     price     <div>     <input type="checkbox" name="price" value="0-1000" class="filters" />0-1000<br />     <input type="checkbox" name="price" value="1000-2000" class="filters" />1000-2000<br />     <input type="checkbox" name="price" value="3000-4000" class="filters" />2000-3000<br />     </div>     colors     <div>    <input type="checkbox" name="colors" value="red" class="filters" />red<br />     <input type="checkbox" name="colors" value="green" class="filters" />green<br />     <input type="checkbox" name="colors" value="blue" class="filters" />blue<br />     </div>     </div> 

javascript

<script type="text/javascript"> $('.filters').on('change',function(){     var price = new array();         $('input[name=price]:checked').each(function(){            price.push($(this).val());         });     var colors = new array();         $('input[name=colors]:checked').each(function(){            colors.push($(this).val());         });      location.href = 'http://localhost/test/javascript.php?price='+price;   });          </script> 

when user click on price option or color option, url should change this

http://localhost/test/javascript.php?price=0-1000&price=1000-2000&colors=red&colors=green 

if user selected single check box should display 1 parameter in url.

is possible javascript ?

$('.filters').on('change',function(){     var price = new array();         $('input[name=price]:checked').each(function(){            price.push($(this).val());         });     var colors = new array();         $('input[name=colors]:checked').each(function(){            colors.push($(this).val());         }); var paramsarray = []     var pricesparams = createparamlist(price,'price');     var colorsparams = createparamlist(colors,'colors');     if (pricesparams)     {         paramsarray.push(pricesparams);     }     if (colorsparams)     {          paramsarray.push(colorsparams);     }     alert('http://localhost/test/javascript.php?'+paramsarray.join('&')); });           function createparamlist(arrayobj, prefix) {     var result = arrayobj.map(function(obj){return prefix+'='+obj;}).join('&');     return result;  } 

jsfiddle


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -