Avatar of MJ
MJFlag for United States of America asked on

How to Get Application ID from Element Using JavaScript?

I'm trying to figure out , using JavaScript, how I can get the app ID (_efdapps_appId=11695 ==> I want 11695 returned) from the element below?
<div class="submit-button">
    <a class="button-details btn btn-primary btn-media" href="https://dev.financial-svcs.com/group/efd/dashboard">View Applications</a> <a class="button-details btn btn-primary btn-media" href="https://dev.financial-svcs.com/group/efd/dashboard/-/applications/apps-full-details?_efdapps_currentStage=credit-review&amp;_efdapps_lifeCycleDescription=This+application+is+being+reviewed.&amp;_efdapps_stepCode=0&amp;_efdapps_appId=11695&amp;_efdapps_programKey=25&amp;_efdapps_decisionCode=18&amp;_efdapps_lifeCycleDecision=Pending+decision&amp;_efdapps_isBeforeDealerPortalLive=false&amp;_efdapps_customerName=Test+More&amp;p_auth=UDdpSWSa">View Full Details</a> 
</div>

Open in new window

I need to support IE 11 so no Xpath.. Also no jQuery, pure JavaScript please.
Thank you!
Web DevelopmentJavaScript* HTML 5jQuery

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
leakim971

test page : https://jsfiddle.net/wcL3sod0/ 

var link = document.evaluate("//a[contains(@href,'efdapps_appId')]", document, null, XPathResult.ANY_TYPE, null).iterateNext();
var efdapps_appId = link && link.href.match(/efdapps_appId=(\d*)/)[1];

Open in new window

ASKER
MJ

Hi Leakim,
That won't work in IE 11. Xpath not supported.
Thanks!
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michel Plungjan

With a simple polyfill you can use the recommended URLSearchParams:
https://jsfiddle.net/mplungjan/thjme91a/ 

(function(w) { w.URLSearchParams = w.URLSearchParams || function(searchString) { let self = this; self.searchString = searchString; self.get = function(name) { let  results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString); return results === null ? null : (decodeURI(results[1]) || 0); };}})(window)


const href = document.querySelectorAll("div.submit-button a.button-details")[1].href;
const urlParams = new URLSearchParams(href);
alert(urlParams.get("_efdapps_appId"));

Open in new window



Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
MJ

Thank you both for your solutions!
leakim971

you welcome