Sending data between pages using query strings with JavaScript

There are two distinct pages that I am working with. My objective is to pass a query string from one page to the other. Here is an example of the code snippet I attempted:

window.location.search = 'id='+hidposid.value; 
window.location.href="editviewposition.aspx";

On the receiving page, I extract the value as follows:

cookie1 = HttpContext.Current.Request.QueryString("id") ' returns ""

Answer №1

<script type="text/javascript">
    $(function () {
        $("#submitButton").bind("click", function () {
            var url = "Page3.htm?username=" + encodeURIComponent($("#nameInput").val()) + "&platform=" + encodeURIComponent($("#platformDropdown").val());
            window.location.href = url;
        });
    });
</script>

<input type="button" id="submitButton" value="Submit" />

Hopefully, this solution will be beneficial for you.

Answer №2

Personally, I prefer a solution similar to:

window.location.replace('update-position.php?id=' + hiddenPositionId.value);

Do you see any potential drawbacks with this approach?

Answer №3

Instead of passing cookies, you are passing a query string here Retrieve it using the following method:

window.location.search = '?id='+hidposid.value;
window.location.href="editviewposition.aspx";

Then, in the code behind file, access the query string like this:

HttpContext.Current.Request.QueryString("id")

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

Resolving Route Problems in Node.js with Express

Currently, I am in the process of developing a website using Express and NodeJS. One issue that I have encountered is related to routing. In my app.js file, I have defined a route that expects a parameter like so: app.get(['/purchase/:purchaseID&apos ...

How can you use Require.context in Webpack to import all .js files from a directory except those ending in `_test.js`?

My objective was to develop a script that accomplishes the following tasks: Import all JS files from a directory excluding those ending in _test.js Set up a module.exports containing an array of module names extracted from those imported files. Initiall ...

The technique of accessing parent props from a child composition component in React

I am trying to reduce every letter prop from the child component, Palata. How can I achieve this? index.js <Block letter="I" mb={16}> <Palata letter="I" start={4} end={9}/> <Wall/> <Empty/> <Palata le ...

Monitoring the content of a page with jQuery and adjusting the size as needed

Here is a code snippet: function adjustContainerHeight() { $('div#mainContainer').css({ 'min-height': $(document).height() - 104 // -104 compensates for a fixed header }).removeShadow().dropShadow({ 'blur&a ...

Is it possible to modify the object's key value when generating an array value with the map function in React?

I have the array object data stored in a variable called hi[0].child. hi[0].child = [ {code: "food", name: "burger"}, {code: "cloth", name: "outer"}, {code: "fruit", name: "apple"}, ] ...

What is the best approach to extracting data from a JSON string in ASP.NET?

Currently, I am utilizing the Sendgrid API to manage mail sending and retrieve statistics. My goal is to save the API response in a database. protected void btnBounces_Click(object sender, EventArgs e) { try { string url = "https://api.sen ...

Injecting services dynamically in angular.js

Utilizing Angular.js and Services, I am able to share data between controllers in the following manner: var mainApp = angular.module("mainApp", []); mainApp.service('CalcService', function(){ this.square = function(a) { //do ...

How come the parameters in my function are being displayed as boolean values in JSDocs when that is not the intended behavior?

I am documenting my journey of following the React tutorial for tic-tac-toe, and I'm puzzled as to why the parameters of my function are showing up as boolean values in JSDocs when they are not supposed to. When I hover over the function with my curs ...

Pushing state history causes browser back and forward button failure

I'm currently utilizing jQuery to dynamically load content within a div container. On the server side, the code is set up to detect if the request is being made through AJAX or GET. In order to ensure that the browser's back and forward buttons ...

The clear function in the template slot of Vue multiselect is not functioning properly

I decided to incorporate the asynchronous select feature found in the documentation for my project. This feature allows me to easily remove a selected value by clicking on 'X'. Below is a snippet of the general component that I use across variou ...

Show a picture upon hovering the button

Welcome to my website. My goal: Show an image when a user hovers over the links. I must be making some silly error, but I can't pinpoint it. This is what I've attempted so far: HTML <ul class="nm"> <li><a href="#">Cork& ...

Displaying Various Items Based on the Language Selected in the Google Translate Widget

Currently, I am in the process of developing a website complete with a shopping cart that will feature different products based on the country of the customer. The client has requested the use of Google Translate to allow for language changes. To accommod ...

Here's a step-by-step guide on how to parse JSON information in JavaScript when it's formatted as key-value

I need to parse the JSON data in JavaScript. The data consists of key-value pairs. Data looks like this: {09/02/2014 15:36:25=[33.82, 33.42, 40.83], 08/11/2014 16:25:15=[36.6, 33.42, 40.45], 07/30/2014 08:43:57=[0.0, 0.0, 0.0], 08/12/2014 22:00:52=[77.99 ...

css background is repeating after the height of the div is reset

I'm working on a project where I want to resize an image while maintaining its aspect ratio to fit the height/width of the browser window. However, every time the code for resizing is implemented, the div height continues to increase with each resize ...

Adding a new line is automatically included at the conclusion during the process of adding an object to an

Within my HTML, I have both a select input and a number input. <select class="span3 align-right-input" ui-select2="{minimumResultsForSearch: -1}" ng-model="info.otherUse" ng-init="info.otherUse=lists.primaryFunctions[0].typeName"> <op ...

Is there a way to streamline this generator without using recursion?

I need to develop a unique value generator that produces values within a specified range. The criteria are: all generated values must be distinct the order of values remains consistent upon each run of the generator each value should be significantly diff ...

"Unlocking the Power of CK Editor for Maximizing Value and Effectively Managing

I have a form with a field titled Description. I am using CKEditor to pass the value entered into this field and store it in my database. Can someone assist me with this? Below is the code snippet: <div id="descriptionMore" style="margin-bottom:20px; ...

Dynamic options can now be accessed and modified using newly computed getters and setters

When using Vuex with Vue components, handling static fields that are editable is easily done through computed properties: computed: { text: { get() { return ... }, set(value) { this.$store.commit... }, }, }, <input type ...

Find the variance between two arrays containing distinct elements

I have 2 arrays with a similar structure as shown below. My objective is to compare each field and store the items from the arrays that differ in a third array. Arr1= [{ state:CA, id:1, name:aaa, product:car, color: white}, {...}] and so forth Arr2= [{ id ...

Tips for handling a multi-step form in React?

Below is the code snippet for the multistep form I have been working on: import clsx from 'clsx'; import React from 'react'; import PropTypes from 'prop-types'; import { makeStyles, withStyles } from '@material-ui/styles ...