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.
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; });
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)
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.
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.
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} });