Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

javascript - jQuery redirect to specific URL based on checkbox click category

I have an multiple category on my page to filter search.

http://localhost/shop/category/produkunggulan/CT0002

Example I have this category:

Brand

$qBrandList = mysqli_query($con, "SELECT P.productid, P.brandid_fk, B.Brandid, B.brand_name FROM tb_product P, tb_brand B WHERE P.brandid_fk = B.brandid AND P.categoryid_fk LIKE '%" . $getCategoryID . "%' GROUP BY B.brandid ORDER BY B.brand_name ASC");
while($dBrandList = mysqli_fetch_array($qBrandList))
{
?>
    <div><label><input name="chkBrand[]" class="chkBrand" type="checkbox" value="<?php echo $dBrandList['brandid_fk']; ?>"/> <?php echo $dBrandList['brand_name']; ?></label></div>
<?php
}

Discount

<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

Now I want when user click the checkbox, it will be directly redirect to the url including the key of category (every click checkbox) and remove the value if uncheck.

Example I click EMORI then FOSSIL, so the URL should be:

http://localhost/shop/category/produkunggulan/CT0002?brand=BR0003,BR0010

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

I don't think you need to use a checkbox to redirect. Simply use input type 'submit'.

<label><input type="submit" name="discount" value="Diskon"/> 

or add onchange event to submit

<label><input type="checkbox" onChange="this.form.submit()" name="discount" value="Y"/> Diskon</label>

also use 'get' method in the tag to show your data at url.

One thing for sure your url wont look as you mentioned rather that it will look as

http://localhost/shop/category/produkunggulan/CT0002?chkBrand%5B%5D=BR0003& chkBrand%5B%5D=BR0010

Here %5B is for'[' and %5D is for ']'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...