Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript jquery checkbox

I'm working on a piece of JavaScript. I'm completely new to JS, But I have a group of checkboxes part of the domainchkb class and with the name, all with different values. I am trying to group those into an array to format into JSON. When executing the code the debugger stops at return this.parent().text();. What am I doing wrong here? Any help would be appreciated.

function format4Cart(){
    var domains;

    var values = $('input[name=domainchkb]:checked').map(function(){
            return this.parent().text();
    }).get();

    domains = "{\"type\" : \"single\", \"data\" : [";

    $.each(values, function(domainIndex,selected_domain){
            domains += "{\"id\" : \""+selected_domain+"\", \"domain\" : \""+whois_response.data.domain+"\"},";
    });
    $(domains).text().replace(/(\s+)?.$/,"");
    domains += "]}";
    domains=encodeURIComponent(domains);
    ajaxAdd2Cart(domains);

}
like image 978
Jackie Craig Sparks Avatar asked Jun 13 '26 16:06

Jackie Craig Sparks


1 Answers

You are trying to call a jQuery method, .parent(), on a DOM element. In order to use a jQuery method on the element, you need to wrap it in a jQuery call:

var values = $('input[name=domainchkb]:checked').map(function(){ 
        return $(this).parent().text(); 
}).get(); 
like image 71
gilly3 Avatar answered Jun 16 '26 10:06

gilly3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!