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.

How do you pull data from a dynamic id = uid?

Discussion in 'jQuery' started by dariusd77, Oct 27, 2016.

  1. #1
    I need to pull the data from an input box. The problem is that the id associated with the input box is dynamic.. If you look at the script below you will see the following ->"uid_loanAmount_16597654821991736" . However that number changes each time a visitor to the site. so next time it could be "uid_loanAmount_234568385923" or some other random number. So when I write the script to pull data from this id I can't include the number portion of the id. Does anyone have any suggestion?

    <input id="uid_loanAmount_16597654821991736" type="number" name="loanAmount" class="form-control input-large input-small no-arrows number" min="0" step="1" aria-describedby="uid_loanAmount_16597654821991736-error" aria-required="true" aria-invalid="false">​

    I want to do soemthing like the following script to extract the input in uid_loanAmount_

    $("#uid_loanAmount_").mouseleave(function(){
    var loanAmount = $this("#uid_loanAmount_") ;
    if (loanAmount.length){
    s.evar17 = loanAmount_ }
    else (// do something
    return false;
    });​

    Thank you.
    SEMrush
     
    dariusd77, Oct 27, 2016 IP
    SEMrush
  2. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Could I do something like this and use a wild card in place of the id #

    $("[name='loanAmount]").mouseleave(function(){
    var loanAmount = $this("#uid_loanAmount_* "); <--
    if (loanAmount.length){
    s.evar17 = loanAmount_ }
    else (// do something
    return false;
    });
     
    dariusd77, Oct 27, 2016 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #3
    There are dynamic ID-selectors. You would use:
    [id^=uid_loanAmount_] to select the beginning of the ID you want to match.

    The dynamic selectors are based on regex-selectors, so for using the end of a dynamic ID, you would use [id$=_loanAmount] for instance (if the number was in the front)
     
    PoPSiCLe, Oct 27, 2016 IP
  4. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Well that didn't work..
     
    dariusd77, Oct 27, 2016 IP
  5. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    So PopSiCLe how do I pull data from the element as shown above?
     
    dariusd77, Oct 27, 2016 IP
  6. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    So, how do I extract the input data from the element as shown above? I need to pull what ever data the visitor input into this field. I am trying to extract this information for my employer for digital analytics they want to collect about their website.
     
    dariusd77, Oct 27, 2016 IP
  7. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    5,851
    Likes Received:
    1,084
    Best Answers:
    22
    Trophy Points:
    400
    #7
    I do something similar with php. Have that id dynamically generated before that input, then echo it in the input id and your jquery code. The page, then of course, has to be a .php page.
     
    qwikad.com, Oct 27, 2016 IP
  8. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    Thanks. Not sure if its PHP but even if it is, I don't have access to the PHP backend
     
    dariusd77, Oct 27, 2016 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Did you try the selector I gave you? If you did, how did you use it, and what was the result ?
     
    PoPSiCLe, Oct 28, 2016 IP
  10. dariusd77

    dariusd77 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #11
    This is the script that works pretty much.

    $("input[name='loanAmount']").mouseleave(function(){
    var loanAmount = $("input[name='loanAmount']").val();
    if (loanAmount.length){
    s.events= "event100 = loanAmount "}
    else {
    return false}
    });
     
    dariusd77, Oct 31, 2016 IP