开发者

jquery, checkboxes within nested div onclick show/hide submit

I have a page that has a series of div's in a shopping-cart system. Each is a product, when checking the checkbox, if there are options available and/or an acknowledge checkbox to be acknowledged before form submit, then keep the button hidden and show a div with another checkbox in it, when that checkbox if exists is checked then show button. The show hide on each div is working properly (existing code), So I am trying to create a function to be called within that function for the onclick event.

where my issue arises is the check to see if another check box [shown in the example as(tmpId == "acknowledge")] does exist and that it is checked also before they can see the submit button, if not show the submit button. This would nee开发者_如何学运维d to work for each product they click the first checkbox on [ie("id= "+feeSID+"_checkbox")]... $("#ocContainer") is the hidden container(with submit) to show if proper checkboxes are checked.. for each product selected.

the first part of each id is a variable generated by a sql query and passed to the function.. My Function:

var feeSID = "";
var feeVAL = "";
var pop = "";

function countChecked(feeSID) {
    var n = $("input:checked").val();
    var tmpId = $(this).attr("name");
    if (tmpId == "acknowledge") {
        console.log("acknowledge Clicked <br />");
    } else {
        feeVAL = $(this).attr("id");
    }
    if (feeVAL == '') {
        return;
    } else {
        if ($("#" + feeSID + "_checkbox:checked")) {
            console.log("id= " + feeSID + "_checkbox");
            var pop = $("#" + feeSID + "_popup").length;
            if (pop > 0) {
                $(":checkbox").click(function () {
                    if (tmpId == "acknowledge") {
                        $("#ocContainer").show();
                    }
                });
            } else {
                $("#ocContainer").show();
            }
        }
    }
}

I hope my explanation was clear. I am getting an error of:

uncaught exception: Syntax error, unrecognized expression: #[object Object]_popup


I think that the exception is possibly caused by this line in your code:

 var pop = $("#"+feeSID+"_popup").length;

At some point in your code, feeSID is assigned to an object. So, you are trying to use an object as part of your selector rather than a string. You need to make sure that feeSID is a string rather than an object before you try using it as part of the selector.


The error was caused by me trying to use an Obj as part of my selector. As Adam Prax had pointed out

var pop = $("#"+feeSID+"_popup").length;

At some point in my code, feeSID is assigned to an object. I solved it by redeclaring the Variable or Object as a string before accessing it again using new String(feeSID);
This solved the issue. I hope it helps someone else, all I could find on google pointed to the use of the syntax @name="name" which is no longer valid syntax in jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜