jQuery Selection Help

How can I select the input value of #assetID from the below when I click on .check

<div class="col-md-12 noPadLeft raHolder" style="margin-top:20px;padding-right:30px;">
                    <input type="hidden" id="assetID" value="91">
                <div class="col-md-7" style="margin-bottom:10px;">
                    <img src="images/postedDateTwitter.png" style="margin-right:5px;">  <span class="postedDate">Scheduled for May 09 2015 at 02:00 PM</span>
                </div>
                <div class="clearfix"></div>
                <div class="col-md-12 borderB noPadLeft noPadRight" style="margin-left:15px;margin-right:15px;">
                    <div class="col-md-9 noPadLeft noPadRight" style="margin-bottom:20px;font-size:14px;color:#696a6c;">
                        Picture of logo.                    </div>
                    <div class="col-md-3  noPadLeft noPadRight text-right">
                        <div class="pull-right"><a href="#">EDIT</a></div><div class="checkDeny pull-right" style="margin-left:10px;margin-right:10px;"></div><div class="check pull-right"></div>
                    </div>
                </div>
            </div>

Open in new window


Here is my current jquery code, just not sure how to select the assetID.

<script>
    $(".check").click(function(){
        $.ajax({
            type: 'POST',
            url: 'submit.php',
            data:
            {
                assetID: $("#ueCoName").val(),
                orgID: <?php echo $orgID;?>,
                userID: <?php echo $userID;?>,
                submitType: 9

            },
            success: function(r)
            {

                $(this).closest(".raHolder").fadeOut("slow");

            }
        });
    });


</script>

Open in new window

LVL 12
Nathan RileyFounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nathan RileyFounderAuthor Commented:
Tried this, but not working.

<script>
    $(".check").click(function(){
        $.ajax({
            type: 'POST',
            url: 'submit.php',
            data:
            {
                assetID: $(this).closest("#assetID").val(),
                orgID: <?php echo $orgID;?>,
                userID: <?php echo $userID;?>,
                submitType: 9

            },
            success: function(r)
            {

                //Doesn't exist
                //alert('Email preferences updated');
                //console.log(r);
                $(this).closest(".raHolder").fadeOut("slow");

            }
        });
    });


</script>

Open in new window

0
Tom BeckCommented:
How about this?
$(this).parent('div.col-md-3').next('input#assetID').val()

Open in new window

0
Nathan RileyFounderAuthor Commented:
Not sure, just ended up getting it done with this, not sure if you way or this is better?

$(".check").click(function(){
        $.ajax({
            type: 'POST',
            url: 'submit.php',
            data:
            {
                assetID: $(this).closest(".raHolder").find('input').val(),
                orgID: <?php echo $orgID;?>,
                userID: <?php echo $userID;?>,
                submitType: 9

            },
            success: function(r)
            {

                //Doesn't exist
                //alert('Email preferences updated');
                //console.log(r);


            }
        });
        $(this).closest(".raHolder").fadeOut("slow");
    });

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Julian HansenCommented:
Confused

#assetId implies an id - which must be unique per page

Therefore, the correct way to do this is
$('#assetId').val();

Open in new window

0
Nathan RileyFounderAuthor Commented:
The assetID is not unique, it's dynamic and inserted during page load via php.  

I have several #assetID's on the page in each of the boxes.  Maybe I named incorrectly?  But seems to be working now with the above solution.
0
Julian HansenCommented:
id's by definition must be unique - if you have multiple elements on your page with the same ID then your page is not valid and you should consider changing your design.

IF you do have multiple then you are going to run in to serious problems with selectors in javascript / jquery.

My advice - change your id's names.
0
Nathan RileyFounderAuthor Commented:
Got it, so it should be a class instead?
0
Julian HansenCommented:
Class - if you have many and want to address many
ID - if you want to target specific element on the page.
If you use the class method and you want to find the element with a given class relative to another element example
<div class="parent">
    <input type="checkbox" class="checkme" />
    <div class="someotherclass">
           <div class="target"> ...</div>
    </div>
</div>

Open in new window

You have various options.

1. Goto the common parent and find from there

$('.checkme').click(function() {
  $(this).closest('.parent').find('.target').html('Some text');
});

Open in new window


2. If the structure of your elements is such that you know exactly where one is in relation to another then

$('.checkme').click(function() {
  $('.target', $(this).next()).html('Just to show this works');
});

Open in new window


Full sample here
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
  $('.checkme').click(function() {
    $('.target', $(this).next()).html('fred');
  });
  $('.checkme2').click(function() {
    $(this).closest('.parent').find('.target').html('Some text');
  });  
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div class="parent">
    <input type="checkbox" class="checkme" />
    <div class="someotherclass">
           <div class="target"> ...</div>
    </div>
</div>
<div class="parent">
  <input type="checkbox" class="checkme2" />
  <div class="someotherclass">
    <div class="target"> ...</div>
  </div>
</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.