I have a jQuery checkbox checked/unchecked function that works well. This is a checkbox for turning a particular URL parameter on or off.  But I believe this code could be written a lot tighter. Does anyone have any suggestions?$('#mapControl').live('click', function(){ var thisUrl = $(location).attr('href');if($(this).is(':checked')) {    var lastFour = thisUrl.substr(thisUrl.length - 4);    var param;    if (lastFour == 'com/') {param='?mapControl=true'} else {param='&mapControl=true'}    thisUrl=thisUrl+param;} else {    $('#urlParam').val(thisUrl);    if (thisUrl.indexOf('?mapControl=true') >= 0){        thisUrl=thisUrl.replace('?mapControl=true','');     } else if (thisUrl.indexOf('&mapControl=true') >= 0){        thisUrl=thisUrl.replace('&mapControl=true','');     } }$('#urlParam').val(thisUrl);});I was given some suggestions (because i erroneously posted on StackOverflow) and was asked to post my question here. So with the feedback I got - I ended up with this code.    function getParam() {    var n;    var myUrl = window.location.href;    var lastFour = myUrl.substr(myUrl.length - 4);    if (lastFour == 'com/') {n='?'} else {n='&'}    return n;}$('#mapControl').on('click', function(){     var thisUrl = window.location.href;    var urlParamObj = $('#urlParam');    if(this.checked === true) {        var lastFour = thisUrl.substr(thisUrl.length - 4);        var param = getParam();        thisUrl=thisUrl+param+'mapControl=true';    } else {        urlParamObj.val(thisUrl);        thisUrl=thisUrl.replace('?mapControl=true','').replace('&mapControl=true','');     }    urlParamObj.val(thisUrl);});I think this is the tightest it could be and I can use the getParam function for other checkboxes.
Determine whether a checkbox is checked or unchecked
javascript;jquery