1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I can't check a checkbox because it has no ID

Discussion in 'JavaScript' started by Alex100, Feb 8, 2023.

  1. #1
    Please take a quick look at this web page...

    https://www.gurufocus.com/stock/AAPL/chart

    At its left side you will see a list of checkboxes (starting with 'Price', 'Revenue', 'Net Income', ...). I would like to write a javascript that will automatically check the 'PS Ratio' checkbox when the page finishes loading. I can inject the script using Tampermonkey.

    The problem is those checkboxes on the left do not have any kind of ID, so I do not know how to call them and change their status. I used the Firefox Inspector tool to check their code, and here it is...

    <li data-v-b3456172="" index="ps_ratio" class="el-menu-item">
      <label data-v-b3456172="" role="checkbox" class="el-checkbox gf">
        <span aria-checked="mixed" class="el-checkbox__input">
    
          <span class="el-checkbox__inner"></span>
          <input type="checkbox" class="el-checkbox__original" value="">
    
        </span>
        <span class="el-checkbox__label"><span data-v-b3456172="" class="indicatorItemName">PS Ratio</span></span>
      </label>
    </li>
    Code (markup):

    As you can see, the 'checkbox' input tag does not have any ID, and its class ('el-checkbox__original') is used by all the other checkboxes in that list.

    So, how could I do this please, what would you recommend?

    Thank you!

    Alex
     
    Last edited: Feb 8, 2023
    Alex100, Feb 8, 2023 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,806
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Can't you give them an id?
     
    sarahk, Feb 8, 2023 IP
  3. Alex100

    Alex100 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    > Can't you give them an id?

    No, I can't because I'm not the owner of the site (to change its code).

    I would like to access the chart on the page without having to check the same checkboxes over and over. Because, as it is now, the user cannot save the settings and use them later for different symbols. You can only save one setting, using a "default" template. But for multiple metrics, you have to manually set the chart each time you visit the page, which is very time-consuming if you use it regularly.

    Alex
     
    Last edited: Feb 9, 2023
    Alex100, Feb 9, 2023 IP
  4. Alex100

    Alex100 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    All right, in the meantime I managed to find a solution using a script written in AutoHotkey - a wonderful programming language for any automation needs!

    Alex
     
    Last edited: Feb 9, 2023
    Alex100, Feb 9, 2023 IP
  5. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #5
    Hi, try the following within Console tab of your browser's Web Dev Tools:
    document.querySelectorAll('[index="ps_ratio"]').length 
    Code (JavaScript):
    If the result is 1 then that ps_ratio element is unique and you could send a click event there.
    I haven't used Tampermonkey though so can't guarantee this:)
     
    hdewantara, Feb 10, 2023 IP
  6. Alex100

    Alex100 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    I will try it, thank you for your suggestion!

    Alex
     
    Alex100, Feb 10, 2023 IP