Sending a parameter to a JavaScript function on a separate page

My current setup involves an aspx page featuring a drop down list. Once a selection is made, I am required to transmit the chosen value to a separate javascript function located within another page. This second page is dedicated to showcasing a map using javascript:

<script>
    var map;
    var ServiceName = "http://some_url//this_is_dynamic_part/MapServer
    ....
</script>

In essence, starting from page1.aspx, my objective is to launch this new page in a fresh window while simultaneously transferring a parameter (in this case, the selected value from the drop down) to substitute "this_is_dynamic_part" within the ServiceName variable.

Answer №1

One way to approach this situation is by utilizing a query parameter. Within the selection handler function, as you construct the URL that will be used with window.open(), simply add ?key=value. In this case, value represents the specific value you wish to transmit, while key denotes a unique parameter name of your choosing.

Subsequently, on the receiving end (second page), accessing the passed values can be done through examining location.search.

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

JavaScript allows for selecting individual IDs by their corresponding numbers

Looking to retrieve numerical IDs <div class="user-view"> <div class="show_user_div"> <div class="disp"> <a href="/profile/name1/">name1</a><br /> <span id="show_a_3"> <a id="ref_show(3)">Show Details</ ...

Incorporating JavaScript into a Node.js project's Jade template

I'm attempting to integrate JavaScript into a jade template page. The code I have written is: script(src='/public/javascripts/scr1.js') and the JavaScript file is located in that directory. Within the script, I have written alert("doesnt wor ...

Is there a way to undo the click event in Javascript?

Is there a way to revert back to the initial position after clicking? I successfully changed the x icon to a + icon on click, but now I'm struggling to reverse that action. I've tried using MOUSEUP and DBLCLICK events, but they aren't ideal ...

If a second instance is hidden, SVG will appear as a mysterious black box

Two separate div elements each contain an identical SVG graphic. If I hide the first div by setting it to "display: none", the SVG in the second div appears as a gray box. This issue is present in both Firefox and Chrome browsers. Any insights into why ...

Iterate over an array in JavaScript and include the elements as parameters in an SQL query

Can I set an SQL string to a variable in JavaScript and populate part of it by looping through an array? Here is the initial SQL: var tag = ["fun", "beach", "sun"]; var sql = "SELECT * FROM myTable " +"WHERE id > 5" //... // L ...

The dilemma of selecting objects in Three.js

Currently, I am developing a small web application that utilizes three.js. However, I have encountered an issue: I created a prototype with my three.js content and everything functions correctly (the canvas size in the prototype matches the browser window ...

Juggling PHP scripts within javascript

Can you help me with a question I have? I am working on multiple JS scripts, such as this one: <script> $('#mapveto1').click(function() { $('#mapveto1').addClass('banned'); $('#map1').text('cobble ...

The try/catch block fails to execute or capture any errors

I'm attempting to create a help command that notifies users in case of closed DMs, but it's not working as expected. Despite encountering an error, the original messages are still sent instead of executing the catch function. I am relatively new ...

Is there a way to access a control within the EditItemTemplate?

I am currently facing an issue with retrieving values from my TextBoxes within the EditItemTemplates of a DetailsView bound to EntityDataSource. Below is the code snippet in question: <asp:DetailsView ID="DetailsView1" DataKeyNames="Name" runat="serv ...

Difference between Vue 3.0 and the Breadcrumb error: Modifying the "items" property

I'm currently in the process of building a website with the vuesax theme and vue cli 3.0. Custom Default Layout: <template> <div class="main-wrapper"> <!---Navigation--> <Navbar :topbarCo ...

Utilizing Loadash for Sorting in VueJs

I am currently utilizing lodash's sortBy function in my code. Below is how it looks: import { sortBy } from 'lodash.sortby'; computed: { visibleInsights() { return sortBy(this.insights.filter(insight => { const id = thi ...

Creating an Angular loading component using the route parameter

When a user clicks on a link in the home component, I want to load a different component based on the URL parameter. For example, if the user is at "/home" and sees a list of links: Link 1 Link 2 Clicking on Link 1 should load the details component with ...

What is the best way to handle waiting for a React context provider that requires time to initialize the value it provides?

In my Next.js application, I have a global context that takes five seconds to compute the value provided: import React, { useContext, useEffect, useState } from 'react'; const GlobalContext = React.createContext(); export const GlobalContextPro ...

Locating the dot character within regular expression challenges

Having difficulty replacing terms like "joe." using a regular expression. Look at the snippet below: var phrases = new Array("joe","sam"); sentence = "joe.id was here as well as sam.id"; for(i = 0; i < phrases.length; i++) { regex = new RegEx ...

How can I use VB codebehind in ASP to display a dialog box to the user asking for a yes or no response?

I am faced with a scenario where a user has chosen a product, the system has retrieved the product record, and the backorder flag has been set. I need to inquire if the user still wants to proceed with including the product in the order. However, I am stru ...

Accessing specific values from a JSON object in JavaScript

I'm fairly new to JSON and have a JSON String that I'd like to access and print to a DIV. I've managed to get it working using the following code snippet: document.getElementById("product_content").innerHTML=javascript_array[5].name; The s ...

AngularJS Large file size

After successfully building the 5 MIN QUICKSTART app, I decided to minify it with webpack following the recommendations in the angularJS docs. To my surprise, the size of the minified AngularJS file turned out to be approximately 700 KB, which is significa ...

Ways to deactivate just the Clicked button in a mapped over component

Utilizing the request variable, I am displaying an array of objects on the page. Each object in the array contains properties such as question, correct_answer, and incorrect_answer. Moreover, I have implemented a state called disable which toggles between ...

Issue with ASP.NET Controls on Different Servers: Error Present on One Server, Absent on Another

My web application is functioning properly on my local machine and our test server, but it encounters a failure in production with the following error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... % ...

Adjust the property to be optional or required depending on the condition using a generic type

const controlConfig = >T extends 'input' | 'button'(config: Config<T>): Config<T> => config; interface Config<TYPE extends 'input' | 'button'> { type: TYPE; label: string; ...