Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

Detect Value in Select Using JavaScript Only (No jQuery)!

If you go to https://apply.essexcredit.com/ on the first page, you'll see a select "What type of loan are you interested in? ". I need to set an event listener on this element and grab the value being selected.(RV or Boat).  Javascript only. Please see image

User generated image
*** I can't touch/change the code on the page. I have to use a TMS to inject my code. ***

Thanks!
Avatar of Daniel Pineault
Daniel Pineault

I think this is what you are after


BLINK LINK REMOVED

Avatar of MJ

ASKER

Hi Daniel,

Unfortunately that won't work. It is a SPA and I'm using a TMS.  I have to attach an event listener to it once it loads and then detect the value selected. Once the virtual page changes, I will detach the listener. 

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Leakim,

Did you mean for the second function to be a "remove"?


Thanks,

MJ

Avatar of MJ

ASKER

Thank you both!

the second function?
your post said you want to detect a value when it change

the following line get the value and set it to title
do what you want with it
I use it to do an alert

var title = found.getAttribute("title" );

Open in new window

Avatar of MJ

ASKER

Hi,

No, originally your code was duplicated? It is not there any longer.


Thanks!

you right, bad copy/paste copy/paste copy/past/... copy/paste

Here is a shorter jQuery version


It will work as long as the select is the 4th in the page and needs to be tested to see if the value changed


$(document).on("click", function() { console.log($("div select:eq(3)").val()) })

Open in new window