0

I am having an issue with the code that I was given as an example from a previous SO question - it is working about 95% but the order array is appearing empty why?

HTML:

<input class="order" value="<?php echo $order; ?>" type="text"  />

JS:

$('body').on("click", "#brands_by_category_submit_btn", function (e) {
         e.preventDefault();               
        var self       = $(this);
        var order      =  []; 
        var id         = $("#manID").data("id");
        var brand_name = $("#brand_name").data("id");
        var data       = grabData(true);

        $(".order").each(function(){
            order.push($(this).text());
        })

        if(data.length)
        {
            var data_array = { 
                id : id,
                brand_name : brand_name, 
                cat_id     : data,
                order      : order, 
                state      : 1
            };
1
  • Psst: var order = $(".order").map(function() { return $(this).val(); }).get(); Commented Sep 22, 2013 at 20:15

2 Answers 2

2

.text() returns the text content of a node, like <p>this text here</p>. An <input /> element doesn't have text content, so $('input').text() will just return an empty string. Your order array should be an array of empty strings then. Maybe you want to extract the values?

$(".order").each(function(){
            order.push($(this).val());
});
Sign up to request clarification or add additional context in comments.

Comments

1

How about:

order.push($(this).val());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.