Liam
Liam

Reputation: 281

Up to Parent back down to different Child JQuery

this is my code for a dynamic page with various amounts of checkboxes. What I would like to know is if the ".parent().children()" property that I have set is possible. I keep getting [Object Object] returned. Any help would be nice.


<div>
            <input name='input1' id='src-1' value = 'input1' type='checkbox'/><br />
            <input name='depnum1' id='depnum-1' value = '' type='text'/><br />
            <input name='depdate1' id='depdate-1' value = '' type='text'/>
        </div>
<script>
    $(document).ready(function() {
        $("#SubDeposit").click(function(){  
            $('input[type=checkbox]').each(function (){
                if($(this).prop('checked')) {
                    //variables
                    var fileLocation = $(this).attr('id');                  
                    var fileLocation = fileLocation.substring(4);
                    alert(fileLocation);            
                    //Variables for inputs that relate to the chekcbox
                    depnum  = ($(this).parent().children('depnum-'+fileLocation));
                    depdate = ($(this).parent().children("depdate-"+fileLocation));
                    alert(depnum);
                    alert(depdate);     
                    console.log(depnum);    
                    console.log(depdate);   
                }
            });
        });
    });
    </script>

Upvotes: 1

Views: 55

Answers (1)

Rich
Rich

Reputation: 1635

I think the problem is that your selector. You want to find the element with id=some value. The selector for id is "#text" so in this case, the correct jquery call would be

depnum  = ($(this).parent().find('#depnum-'+fileLocation));
depdate = ($(this).parent().find("#depdate-"+fileLocation));

Upvotes: 3

Related Questions