Send JavaScript variable using a query parameter

I am working on passing a JavaScript variable across all pages in my project. The goal is to calculate the total value from various pages and display it at the end of navigation. Below is an example of my JS code:


    <script>
    $(document).ready(function() {
    $('input[name=q1]').click(function() {
      var selectedValue = $(this).val(); 
      if($(this).val() == "A3") 
      var count=1;
      else
      var count=0;
        });
    });
</script>

HTML structure:


<form name="login" action=“page2.html" method="post">
    <section class="heading">
     <p><strong>Test1</strong></p>
    </section>
    <p class="pstyle">1st page</p>
     <table>
        <tr>
            <td>
                <input type="radio" name="q1" id="q1A1" required value="A1" />
                Topic1
            </td>
            <td style="padding-left: 30px;">
                <input type="radio" name="q1" id="q1A2" required value="A2"/>
                Topic2
            </td>
        </tr><br>
        <tr style="height: 77px;">
            <td>
                <input type="radio" name="q1" id="q1A3" required value="A3"/>
                Topic3  
            </td>
            <td style="padding-left: 30px;">
                <input type="radio" name="q1" id="q1A4" required value="A4"/>
                Topic4          
            </td><br>
        <tr>
            <td>
                <input type="Submit" value=“Next “Page style="font-size: 40px;"/>
            </td>
            <td style="padding-left: 30px;">
                <input type="Submit" value="Cancel" style="font-size: 40px;"/>
            </td>
        </tr>
    </table>        
</form>

I'm looking for suggestions on how to pass the "Count" variable to another page using query string instead of local storage. Any advice would be greatly appreciated. Thank you.

Answer №1

Implement

The PHP include statement

to import JavaScript code into your documents right from the beginning. By doing so, any modifications made to your code will ensure consistency across all files.

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

What is the process for implementing custom CSS styles in Cognos?

I've been working on creating Cognos reports and I'm looking to change the overall design of some specific ones (prompt pages and report pages). Is there a way for me to use different custom CSS files for each individual report? If that's ...

An Alternative Approach for Executing a Function within an AngularJS Directive

I am currently working on a unique element directive that displays a user's picture and name. This directive has various configuration attributes, one of which is the uc-on-hover attribute. The purpose of this attribute is to determine what element sh ...

Verify if all the words commence with a certain character using regular expressions

I am working on form validation using Angular, and I am trying to verify if all words in a string start with the letter 'Z'. I am implementing this using a pattern so that I can dynamically change the input's class. So far, this is what I h ...

What is preventing the hidden attribute from being edited within a modal window?

Recently, I've come across an issue with changing the hidden attribute inside a modal. No matter what I try, I can't seem to change the value of it. Here is the code snippet I attempted to use: function SignUp() { $("#regModal").modal( ...

The CSS styles can vary depending on the web browser being used

Require assistance with my CSS. I designed an HTML/CSS widget on Blogger using my own expertise, but now facing some issues. The trouble arises with the image on the front left in the code. While it displays correctly on Google Chrome, aligned with the te ...

Conceal elements and offspring in D3.js through the utilization of JavaScript or jQuery

I am currently customizing a fantastic force directed layout created by @eyaler (http://bl.ocks.org/eyaler/1058611) that offers multiple options. My goal is to conceal a specific node with its children using jQuery or D3 along with JavaScript, not directly ...

Have the events finished loading after using the gotoDate function in fullcalendar?

I have a scenario where I need to change the view by calling gotoDate and then apply additional classes using jQuery to selected events after clicking a button. The issue arises because the events are loaded via ajax, causing the addition of classes to oc ...

Position a div off-center using CSS styling

Currently, I am utilizing a flexbox to center a div inside another div, akin to a dialog window that pops up at the center of the screen when required. The functionality is sound, but aesthetically it would be more pleasing if the space above and below th ...

React: Incorporating .map for nested arrays. Ensure each child component within the list is assigned a distinct "key" property

I have an array called navMenuItems that contains data for building a navigation menu with links and link names. Each item in the array may also contain child links, similar to the mobile menu on https://www.w3schools.com/. However, I'm encountering a ...

How can we reduce the size of a JSON object in Typescript before sending it to the client?

Currently, I am faced with a common challenge. I have a database object that is a standard JS object originating from a document database, and my goal is to transmit this object to the client. However, certain fields contain sensitive information that shou ...

The data type 'string' cannot be assigned to the data type 'Position'

Currently, I am in the process of converting React js to typescript. The component being used is a Class Component. I would like to obtain CSS settings through props and apply them to an element. How can I resolve this issue? render(){return( <span st ...

Pattern to locate a CSS class identifier

I've been working on creating a regex to match valid CSS class name structures. Currently, my progress looks like this: $pattern = "([A-Za-z]*\.[A-Za-z]+\s*{)"; $regex = preg_match_all($pattern, $html, $matches); However, there are certai ...

What causes the alignment of text to be overridden by the presence of a floating element?

https://jsfiddle.net/u0Ltgh3e/68/ .text { width: 50%; text-align: justify; } I am currently developing a custom formatting tool for a specific purpose and I am attempting to create a two-column layout similar to the one demonstrated in this Jsfiddle l ...

Tips for handling a disabled button feature in Python Selenium automation

When trying to click this button: <button id="btn-login-5" type="button" class="m-1 btn btn-warning" disabled="">Update</button> I need to remove the disable attribute to make the button clickable. This ...

What is the best way to update a local variable in JavaScript using Ajax requests?

function validate_authentication(){ var is_authenticated = false; $.ajax({ type: "POST", url: "/account/islogin/", data: "", async: "false", success: function(data) { if (data == "null") { ...

Ensure that all of the <li> elements within a <ul> container have equal widths

I've been grappling with this problem for the past day, and despite restarting from scratch multiple times, I can't seem to make a horizontal CSS flyout header function as intended. The dropdown section should expand to fit the content width (id ...

When the audio on the device is in use, the video will not play and vice versa

Whenever my video starts playing, the audio from my device (such as iPod or Spotify) stops. If I try to play the audio manually while the video is playing, the video freezes. Interestingly, when I tested playing an audio file directly within the app, it wo ...

Click to be redirected to the same page on a different store

I have been working on a Shopify project where I implemented a pop-up that appears when the page loads, prompting users to choose between the US and UK websites. Once a user clicks on one of the options, the pop-up either closes (UK) or redirects them to ...

Combining model with a string in an expression in AngularJS version 1

Can this text be transformed into an expression using ecmaScript 2015? The || operator seems to be causing issues. {{ ::$ctrl.realEstateProjectCurrentProduct.housingTax + ' €' || $ctrl.noDataMessage }} ...

What is the best way to extract the lodash score from a URL using JSON parsing?

Can someone help me figure out how to extract and store the names from a URL into an array, then parse JSON data to retrieve the lodash score and convert it into a whole number? Any assistance would be greatly appreciated. <head> <title> ...