How do you extract data from a dynamic Id -> "uid" to be capture in an event variable

dariusd91806962

27-10-2016

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 imput in this field.
$("#uid_loanAmount_").mouseleave(function(){
 var loanAmount = $this("#uid_loanAmount_") ;
if (loanAmount.length){
s.event17 = loanAmount_ }
else (// do something
     return false;
});

Accepted Solutions (1)

Accepted Solutions (1)

dariusd91806962

31-10-2016

arob87 wrote...

  1. $("input[name='loanAmount']").mouseleave(function(){
 
  1. var loanAmount = $("input[name='loanAmount']").val();
  2. if (loanAmount.length){
  3. s.events= "event100:"+loanAmount;}
  4. else {
  5. return false}
  6. });

You need to add a colon for event serialization and take the variable name out of quotes so that the variable passes through

 

Thank you, this worked perfectly.....smileyyes

Answers (8)

Answers (8)

andrew_r-GrfLbX

31-10-2016

$("input[name='loanAmount']").mouseleave(function(){
var loanAmount = $("input[name='loanAmount']").val(); if (loanAmount.length){ s.events= "event100:"+loanAmount;} else { return false} });

You need to add a colon for event serialization and take the variable name out of quotes so that the variable passes through

dariusd91806962

31-10-2016

so this script works

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

but the s.events portion does not capture the numerical value stored in the variable loanAmount.. I am not sure how to pass it to an s.event variable. I did verify that the numerical value is being captured in this script because I passed it to an s.prop variable to test it. and it pulls the acutally numerical value that is typed into the input box. But it does not pass it to the s.event variable. what I get instead is the literal text "loanAmount" <- this is what shows up in the s.event variable. I also set the s.event to currency. So can anyone suggest how to pass the actual numerical integer to the s.event variable.  

Thanks

andrew_r-GrfLbX

28-10-2016

I'm also assuming you don't have DTM and this is going directly on the page so you'd have something like:

$("input[name='loanAmount']").mouseleave(function(){ var loanAmount = $("input[name='loanAmount']").val(); if (loanAmount.length){ s.eVar17 = loanAmount } else { return false} });

dariusd91806962

27-10-2016

Darius Dempsey wrote...

arob87 wrote...

assume you're using jQuery from the above and that name="loanAmount" is always consistent so could you not use the following selector?

$("[name='loanAmount']").....

 

 

 

I guess I could. I'm not very good at Jquery, so could you elaborate a little bit more with the code?  

 

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

dariusd91806962

27-10-2016

OK I see what you are saying. That would allow me identify the element, however how do I take care of this part of the code

 var loanAmount = $this("#uid_loanAmount_") ; This is where the data is being stored. So how do I pull it from here. I'm not really good with HTML, so unless you are saying that the input value is some how stored within all parts of the element. I'm not sure how I can pull the input data from the element meaning I could do this  -> var loanAmount =$this(name='loanAmount') and it would extract the input value.. lets say its $305,000.. 

dariusd91806962

27-10-2016

arob87 wrote...

assume you're using jQuery from the above and that name="loanAmount" is always consistent so could you not use the following selector?

$("[name='loanAmount']").....

 

 

 

I guess I could. I'm not very good at Jquery, so could you elaborate a little bit more with the code?  

andrew_r-GrfLbX

27-10-2016

assume you're using jQuery from the above and that name="loanAmount" is always consistent so could you not use the following selector?

$("[name='loanAmount']").....