5 Replies - 2320 Views - Last Post: 15 April 2013 - 12:45 AM

#1 HouseFinch  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 14-April 13

How can I select a dropdown list in a table cell using JQuery?

Posted 14 April 2013 - 01:52 AM

Hi, Iím using JQuery version 1.8.11 with IE10. I have a table with a simgle row. the table id is #listTable, the <tr>id is #listTableRow and the <td> id is #days. The row has a number of cells and in each cell there is a dropdown list with the same id: #searchString. I want to be able to select the the dropdown list in the third cell and set its option to option:first.. Iíve been able to select the td with the code below but not the specific dropdown list.. How can I select the 3rd dropdown list in a table?

<script type="text/javascript">
         
 
 
            $(document).ready(function () {
                var nos = $('#listTable #searchString').length;
               
                $.each($checkboxes, function () {
                    if ($(this).is(':checked')) {
                     
$('#listTable #days:nth-child(3)').css('border', '2px dashed blue');
                       
                });
 
            });
                                 
           </script>
 



Is This A Good Question/Topic? 0
  • +

Replies To: How can I select a dropdown list in a table cell using JQuery?

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6108
  • View blog
  • Posts: 23,666
  • Joined: 23-August 08

Re: How can I select a dropdown list in a table cell using JQuery?

Posted 14 April 2013 - 09:21 AM

This is flawed thinking. id values should, by their very definition, be unique. You should make it unique in some way or use a CSS class value to identify these dropdowns as a group.

EDIT: Actually, I'm not sure from your description what is going on. You have a td with cells WITHIN the td?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3822
  • View blog
  • Posts: 13,544
  • Joined: 12-December 12

Re: How can I select a dropdown list in a table cell using JQuery?

Posted 14 April 2013 - 09:30 AM

Also, you don't need to use the nth-child (css) selector, when jQuery has eq().

$('#yourtableid .yourcheckboxclassname').eq(2)    // eq is zero-indexed

although there are many other ways to refer to the checkbox. Even just:

$("#yourtableid input[type='checkbox']").eq(2)    // eq is zero-indexed

This post has been edited by andrewsw: 14 April 2013 - 09:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 HouseFinch  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 14-April 13

Re: How can I select a dropdown list in a table cell using JQuery?

Posted 14 April 2013 - 10:49 AM

View PostJackOfAllTrades, on 14 April 2013 - 09:21 AM, said:

This is flawed thinking. id values should, by their very definition, be unique. You should make it unique in some way or use a CSS class value to identify these dropdowns as a group.

EDIT: Actually, I'm not sure from your description what is going on. You have a td with cells WITHIN the td?


Sorry about the concussion. The td is inside a tr.
Was This Post Helpful? 1
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3822
  • View blog
  • Posts: 13,544
  • Joined: 12-December 12

Re: How can I select a dropdown list in a table cell using JQuery?

Posted 14 April 2013 - 11:04 AM

View PostHouseFinch, on 14 April 2013 - 05:49 PM, said:

Sorry about the concussion. The td is inside a tr.

LOL Did you bang your head on the table? :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 HouseFinch  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 14-April 13

Re: How can I select a dropdown list in a table cell using JQuery?

Posted 15 April 2013 - 12:45 AM

View Postandrewsw, on 14 April 2013 - 11:04 AM, said:

View PostHouseFinch, on 14 April 2013 - 05:49 PM, said:

Sorry about the concussion. The td is inside a tr.

LOL Did you bang your head on the table? :bigsmile:/>


Thanks for the help Andrewew. I added the class and that did the job.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1