NetTalk Central

Author Topic: Get ramdom ID from CreateButton  (Read 3203 times)

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • Email
Get ramdom ID from CreateButton
« on: March 06, 2019, 12:33:33 AM »
Hi Bruce

It could be really nice if it was possible to get the ID from the CreateButton methode, back in some way - or maybe it is?
I can capture it from the Packet object via StringTheory, but it could be nice if there was a little more straightforward way.
Then it would make it possible to manipulate the individual buttons - click, css etc via JavaScript.
Maybe it's possible to return the ID via the method in the future?

Regards Niels

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Get ramdom ID from CreateButton
« Reply #1 on: March 06, 2019, 02:43:57 AM »
There are many more ways to select an element other than the ID. 

*   $("*")   All elements
#id   $("#lastname")   The element with id="lastname"
.class   $(".intro")   All elements with class="intro"
.class,.class   $(".intro,.demo")   All elements with the class "intro" or "demo"
element   $("p")   All <p> elements
el1,el2,el3   $("h1,div,p")   All <h1>, <div> and <p> elements
        
:first   $("p:first")   The first <p> element
:last   $("p:last")   The last <p> element
:even   $("tr:even")   All even <tr> elements
:odd   $("tr:odd")   All odd <tr> elements
        
:first-child   $("p:first-child")   All <p> elements that are the first child of their parent
:first-of-type   $("p:first-of-type")   All <p> elements that are the first <p> element of their parent
:last-child   $("p:last-child")   All <p> elements that are the last child of their parent
:last-of-type   $("p:last-of-type")   All <p> elements that are the last <p> element of their parent
:nth-child(n)   $("p:nth-child(2)")   All <p> elements that are the 2nd child of their parent
:nth-last-child(n)   $("p:nth-last-child(2)")   All <p> elements that are the 2nd child of their parent, counting from the last child
:nth-of-type(n)   $("p:nth-of-type(2)")   All <p> elements that are the 2nd <p> element of their parent
:nth-last-of-type(n)   $("p:nth-last-of-type(2)")   All <p> elements that are the 2nd <p> element of their parent, counting from the last child
:only-child   $("p:only-child")   All <p> elements that are the only child of their parent
:only-of-type   $("p:only-of-type")   All <p> elements that are the only child, of its type, of their parent
        
parent > child   $("div > p")   All <p> elements that are a direct child of a <div> element
parent descendant   $("div p")   All <p> elements that are descendants of a <div> element
element + next   $("div + p")   The <p> element that are next to each <div> elements
element ~ siblings   $("div ~ p")   All <p> elements that are siblings of a <div> element
        
:eq(index)   $("ul li:eq(3)")   The fourth element in a list (index starts at 0)
:gt(no)   $("ul li:gt(3)")   List elements with an index greater than 3
:lt(no)   $("ul li:lt(3)")   List elements with an index less than 3
:not(selector)   $("input:not(:empty)")   All input elements that are not empty
        
:header   $(":header")   All header elements <h1>, <h2> ...
:animated   $(":animated")   All animated elements
:focus   $(":focus")   The element that currently has focus
:contains(text)   $(":contains('Hello')")   All elements which contains the text "Hello"
:has(selector)   $("div:has(p)")   All <div> elements that have a <p> element
:empty   $(":empty")   All elements that are empty
:parent   $(":parent")   All elements that are a parent of another element
:hidden   $("p:hidden")   All hidden <p> elements
:visible   $("table:visible")   All visible tables
:root   $(":root")   The document's root element
:lang(language)   $("p:lang(de)")   All <p> elements with a lang attribute value starting with "de"
        
[attribute]   $("[href]")   All elements with a href attribute
[attribute=value]   $("[href='default.htm']")   All elements with a href attribute value equal to "default.htm"
[attribute!=value]   $("[href!='default.htm']")   All elements with a href attribute value not equal to "default.htm"
[attribute$=value]   $("[href$='.jpg']")   All elements with a href attribute value ending with ".jpg"
[attribute|=value]   $("[title|='Tomorrow']")   All elements with a title attribute value equal to 'Tomorrow', or starting with 'Tomorrow' followed by a hyphen
[attribute^=value]   $("[title^='Tom']")   All elements with a title attribute value starting with "Tom"
[attribute~=value]   $("[title~='hello']")   All elements with a title attribute value containing the specific word "hello"
[attribute*=value]   $("[title*='hello']")   All elements with a title attribute value containing the word "hello"
        
:input   $(":input")   All input elements
:text   $(":text")   All input elements with type="text"
:password   $(":password")   All input elements with type="password"
:radio   $(":radio")   All input elements with type="radio"
:checkbox   $(":checkbox")   All input elements with type="checkbox"
:submit   $(":submit")   All input elements with type="submit"
:reset   $(":reset")   All input elements with type="reset"
:button   $(":button")   All input elements with type="button"
:image   $(":image")   All input elements with type="image"
:file   $(":file")   All input elements with type="file"
:enabled   $(":enabled")   All enabled input elements
:disabled   $(":disabled")   All disabled input elements
:selected   $(":selected")   All selected input elements
:checked   $(":checked")   All checked input elements
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Get ramdom ID from CreateButton
« Reply #2 on: March 06, 2019, 03:00:49 AM »
Having said that, I understand where you're coming from. 

I think that the potential for a large number of buttons necessitated the ID generation method.  It prevents conflicting ID's. 
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • Email
Re: Get ramdom ID from CreateButton
« Reply #3 on: March 06, 2019, 10:38:53 PM »
Hi Don

Thanks for the feedback.
I know I can find the elements through all kinds of methods via jquery. But the whole thing would just be so much easier if I had the exact ID on the elements I should address.
My goal is to place relevant javascript in each browse row, which refers to other elements (buttons) in the same row.
Does it make sense?

Regards Niels

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11174
    • View Profile
Re: Get ramdom ID from CreateButton
« Reply #4 on: March 07, 2019, 01:05:04 AM »
the main problem withthe ID is that'll change if the button is refreshed - meaning that using the ID from elsewhere on the row is not ideal.

>> My goal is to place relevant javascript in each browse row, which refers to other elements (buttons) in the same row.

My suggestion would be to add a different identifier to the button. There are lots of ways of doing this, but perhaps the easiest is to add a css class name to the button. The css class doesn't even need to exist. Then you can do the appropriate jQuery selector to "find the button in this row with this class".

It doesn't have to be the class, it could be anything, but class is easy. You might have to play a bit to get the "on this row" limit, depending on where the button is relative to the javascript.

cheers
Bruce

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 420
    • View Profile
    • Email
Re: Get ramdom ID from CreateButton
« Reply #5 on: March 07, 2019, 05:45:06 AM »
Why haven't I thought of that. Using a class is brilliant.
Thanks, it solves my challenge in an easy and excellent way.