user3733831 user3733831 - 11 months ago 57
jQuery Question

How can I fix this jquery issue?

I do have a

field to insert date and also have a
for select category.

When changing the date input field I want to make the page reload with attaching date and category values in the URL.

NOTE: Here I want to attach category value if it is not empty.

This is how I tried it. But it doesn't work for me.

$("#date").change(function() {
var c = $("#category").val();
var d = $(this).val();
if(c.length === 0 ) {
var cat = "$cat="+c;
} else {
var cat;


This is the output, when category ID is not empty.


Can anybody help me to fix my problem?
Thank you.

Prs Prs

You could try this approach. Put only what you have.

$("#date").change(function() { 
    var url = ''; 
    var c = $("#category").val(); 
    var d = $(this).val(); 
    if(c.trim().length) { url+='&cat='+c } 
    if(d.trim().length) { url+='&todate='+d }