What is the method for extracting URI value in JavaScript?

Similar Question:
How can I get query string values?
grab query string using javascript

I am working with a form URI where I need to extract a specific ATTRIBUTE value and then assign that value to a corresponding form field.

For example, consider the following string:

"formFieldName=UXCopy%3Abody&FCKAssetId=Variables.ContentDetails%3Aid&fielddesc=Body&FCKName=homecopy&AssetType=UXPage&StartItem=1299862617913&FCKAssetType=UXCopy&cs_environment=addref&pagename=OpenMarket%2FXcelerate%2FActions%2FNewContentFront&embedtype=link&adidiii=ssssssss&childtypes=UXDocument%2CUXEmbed%2CUXGoogleMap%2CUXImage%2CUXSocialMediaLink%2CUXPage&IFCKEditor=true&title=New&cancelpage=OpenMarket%2FXcelerate%2FActions%2FAddRefFront&assetid=Variables.assetid"

In this scenario, I aim to retrieve the value of adidiii and assign it to the corresponding form field.

Answer №1

const updatedURL = previousURL.replace(/&adidiii\=.+[&$]/, "&adidiii=" + encodeURIComponent(**SomeOtherFormField**) + "&")

If you only need to extract a parameter from the URL, use this method:

function extractURLParam(URL, parameter)
{
    const match = URL.match(new RegExp("[\?&]" + parameter + "=([^&]+)"));
    return match[1] ? decodeURIComponent(match[1]) : null;
}

Answer №2

Follow this simple procedure to extract the desired values from the URL.

function extractURLValues() {
    var values = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(match,key,val) {
        values[key] = val;
    });
    return values;
}

To retrieve the value of customID, use the code snippet below.

var id = extractURLValues()["customID"];

alert(id);

This should guide you in the right direction.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Deploying NextJS: Error in type causes fetch-routing malfunction

Encountering a mysterious and funky NextJS 13.4 Error that has me stumped. Here's a summary of what I've observed: The issue only pops up after running npm run build & npm run start, not during npm run dev The problem occurs both locally and ...

What is the best way to populate a dropdown menu with data and enable users to search for specific items by typing them in?

I need assistance with populating data in a drop-down box that is not pre-defined. The data needs to be dynamically created and then displayed in the drop-down box. Currently, the data is being shown using check boxes, but I want it to appear in a drop-dow ...

A guide on transferring received data from dataService within the parent component to the child component in Angular2

Within the context of my application, there exists a parent component named app-parent and a child component called app-child. In app-parent, I retrieve data from a DataService. @Component({ selector: 'app-parent', providers: [DataService] ...

Using JavaScript regex to match repeating subgroups

Can a regular expression capture all repeating and matching subgroups in one call? Consider a string like this: {{token id=foo1 class=foo2 attr1=foo3}} Where the number of attributes (e.g. id, class, attr1) are variable and can be any key=value pair. C ...

Generate seamless rotation within a specified time frame (+- x%)

I need to rotate a cube in my scene with a specific initial speed within a specified timeframe. The end angle of the cube must match the starting angle. To account for potential variations, I am allowing for a deviation of up to 5% in the timeframe. Cu ...

Exploring the concept of passing 'this' as a parameter in JavaScript

<button type="button" aria-haspopup="dialog" aria-controls="b" onclick="openLayer($('#b'))"> button</button> <div role="dialog" id="b"><"button type="button">close<"/button></div> function openLayer(target){ ...

"Null" is the value assigned to a JavaScript variable

I am encountering an issue on line 30 with the $.each(data.menu, function (). The console is indicating that "data is null". Can someone clarify what's happening? Thank you! function getFoodMenuData () { var url = 'http://localhost:88 ...

Vue3: Pinia store data not being received

Having trouble retrieving Pinia data using the Composition API after a page reload? I'm utilizing Vue to parse fetched JSON data. Despite being new to the Composition API, I can't pinpoint what's causing the issue even after going through th ...

Angular 6 Calendar Template issues with parsing: Unable to link to 'view' as it is not recognized as a valid property of 'div'

I am in the process of developing an application that utilizes this angular calendar. My tech stack includes Angular 6 with AngularFire2 and Firebase. Below is my app.module.ts file: import { BrowserModule } from '@angular/platform-browser'; imp ...

What is the best method for creating thumbnail URLs for video files in HTML with JavaScript?

I am facing an issue with generating a thumburl for uploaded video files. After dynamically creating an input file and uploading local video files, I am able to retrieve the name and size of the file along with other information as shown in the screenshot ...

Retrieve each individual element from an array sequentially using jQuery

I am looking to retrieve elements from an array one at a time and only display each element after completing a certain action with the previous one. Here’s an example: var elems = ['Apple','Orange','Banana'], i = 0; ...

Having trouble with the unresponsive sticky top-bar feature in Zurb Foundation 5?

According to the information provided on this website, it is recommended to enclose the top-bar navigation within a div element that has both the class "contain-to-grid" and "sticky". However, I have noticed that while the "contain-to-grid" class exists in ...

Insert a new, unique div onto an HTML webpage using JavaScript, ensuring no duplicates are created

Having an issue with this code snippet where nothing is being added. It seems like the variable result may not be taking a number or something else, but I'm not entirely sure why. $(document).ready(function () //document.getElementById(1).style. ...

Can using Gulp 4 to import or bundle Bootstrap 5 or Popper.js create a LICENSE.js file?

I am currently working on a project using Gulp 4 and Webpack 5 with Bootstrap 5. During the script bundling process, I have noticed that Gulp generates a bundle.js file as expected, but it also creates a bundle.js.LICENSE.js file. After examining my build ...

What are the reasons behind the min and max range method not providing accurate results?

I am in need of a method that can verify if a given value falls within the valid range of -064.000000 to -180.000000 and 142.000000 to 180.000000. The structure of my ranges object is as follows: "ranges": { "range1": { "min& ...

Encountering issues with resolving dependency tree post updating node, specifically with node-sass dependency causing failure

Following the update to the latest version of Node.js, I encountered error messages when attempting to use npm audit fix --force. It appears that resolving dependency tree issues is proving to be difficult. Despite extensive research and trying various s ...

What causes useEffect to be triggered multiple times, even when it is dependent on another useEffect function that is being executed repeatedly?

I have a specific requirement that involves using two useEffect hooks. First useEffect is used to set the latitude and longitude in the state with an empty dependency array. useEffect(() => { navigator.geolocation.getCurrentPosition(geo = ...

Using both the variable and the JSON format from the Google Maps API

I am trying to display the coordinates from the input fields on a map using Google Maps API. However, I am facing an issue with passing the values to the script. Below is the code snippet: <input type="text" id="latitude" class="form-control" /> ...

Creating a direct connection between a parent node and all of its children in OrgChartjs

Can I connect all children directly to one parent in Balkan OrgChart.js? This is my starting point based on the documentation of OrgChart.js. window.onload = function () { OrgChart.templates.family_template = Object.assign({}, OrgChart.templates.ana); ...

Attempting to execute JavaScript within HTML files that have been incorporated using Angular

My website has a menu designed in HTML, and instead of manually adding it to each page (which would make updating changes tedious), I am using Angular to include it dynamically (<div ng-include="menu.html"></div>). I've got some JavaScrip ...