I need help with creating a script that will output each value of an array without including the variable name, but with unique text before each

I need assistance with creating a script that can output the values from an array (obtained from a form) without displaying the variable names. Additionally, I want to include customized text before each value such as "You pledged $ (value they entered), Your name is (value they entered), etc." The challenge lies in achieving the second part of my requirement. It's currently better than having "myfunkyvariablename=value" displayed, but simply printing the values doesn't provide all the necessary information to the user. Is there a solution for this dilemma?

<script type="text/javascript>
/* <![CDATA[ */
var formData = location.search;
formData = formData.substring(1, formData.length);
while (formData.indexOf("+") != -1) {
formData = formData.replace("+", " ");
}
formData = unescape(formData);
var formArray = formData.split("&");
for (var i=0; i < formArray.length; ++i) {
var printBegin=formArray[i].search("=") +1 
document.write(formArray[i].substring(printBegin) + "<br />");
}

/* ]]> */
</script>

If anyone could provide assistance on this matter, it would be greatly appreciated.

Answer №1

After extensive research, I have discovered a solution that hinges on having a comprehensive understanding of all the elements within the form. The snippet above effectively removes unwanted variable names from the form array. To proceed, you must create a secondary array containing elements corresponding to those in the form, attributing values that dictate the desired output. Next, merge these two arrays into a table format like so:

document.write("<table>")

var formData = location.search;
formData = formData.substring(1, formData.length);
while (formData.indexOf("+") != -1) {
    formData = formData.replace("+", " ");
}
formData = unescape(formData);
var formArray = formData.split("&");

for (var i=0; i < formArray.length; ++i) {
    var printBegin=formArray[i].search("=") + 1; 

    document.write("<tr><td>" + responseArray[i] + "</td><td>" + formArray[i].substring(printBegin) + "</td></tr>");
}

document.write("</table>");

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

Is it possible to export survey responses as JSON or text files within SurveyJS?

I am currently developing a web survey using SurveyJS. While I have successfully created the survey form, I am facing difficulties in saving the data on my local computer once the survey is completed. Does anyone know how to save the collected data as JSO ...

Removing an unnamed cookie

A mysterious cookie mysteriously appeared on my website, courtesy of Sharethis (value "sharethis_cookie_test"). This cookie is causing all sorts of session issues for me specifically on Chrome. Despite removing the sharethis plugin from my site, this pesky ...

Close ui-bootstrap typeahead menu only when a row is manually chosen

I have set up this jsBin to show the problem I am facing. When you visit the link and try to type "Five," the expected behavior would be to type "Five" and then press tab. However, in this case, you need to type "Five" and then either escape or click outsi ...

Issues with making cross-domain requests using jQuery and PHP

I have stumbled upon a similar question that has been asked before, but unfortunately, the answer provided did not give me enough guidance to identify where my code is incorrect. I apologize if this question resembles a previously existing one; I have spen ...

Exploring the importance of security measures when incorporating custom JavaScript code within a Java application

I'm currently working on a Java project where we aim to allow end-users to define variables that are calculated based on a set of given primitive types or string variables. Once all the given variables are assigned specific values, the calculations wi ...

Arranging nested arrays in Swift 3

let myItems: [[String]] = [ ["1", "picture1.png", "John", "Smith"], ["2", "picture2.png", "Mike", "Rutherford"], ] Can someone explain how to sort the elements in myItems based on the first and second items, either in ascending or descending order ...

Encountered a snag while executing Powershell with Selenium: Error message - unable to interact with

Looking to update a textarea with a value? The script below triggers an error stating "element not interactable". This occurs because the textarea is set to "display:none". However, manually removing the "NONE" word allows the script to successfully set th ...

Unable to integrate bower with gulp for automation

I am trying to get gulp to run the installation of all files listed in my bower.json. However, despite writing the code below, it is not working and I'm not seeing any errors. What could be causing this issue? var gulp = require("gulp"); var bower = ...

Discover the best way to highlight a specific area using imgareaelect

The code snippet provided is for uploading an image and performing some operations on it using jQuery UI Tooltip. The code includes various scripts and stylesheets to handle the image upload functionality. After uploading an image, the code checks if the ...

Tips on how to retrieve the current value of a scope variable in jQuery

When making a $http request to save data on the server and receiving a json response, I want to show an Android-style message using Toast for either success or failure based on the response. Initially, I set a scope variable to false $scope.showSuccessToa ...

Regular expressions or regex can be used to match the initial letter or letters of various words

Struggling with regex? After searching for an hour, the best solution found was this one. Still unable to crack it though... Here's what I need: Have a JS array that needs to be filtered. The array looks like: [ 'Gurken halbiert 2kg', &a ...

Effective ways to transmit a variable array from an HTML document to a PHP server

Is there a better method for transferring a variable array from HTML to PHP? I attempted to use the serialize function, but it doesn't seem to be functioning correctly. Any suggestions would be greatly appreciated. //HTML var arrayTextAreasNames = [ ...

When determining the extent to which client-side code should be utilized

As I work on developing a website with an extensive admin section, I am contemplating the amount of logic to incorporate on the client side. Using Ruby on Rails, I have the option of generating admin pages solely server-side with light client-side code for ...

Calculating numbers with Math.ceil will result in an increase of 1

After using Math.ceil, one value was rounded up to 50 and the other to 80. However, when I added these two values together, the result unexpectedly turned out to be 131. console.log(Math.ceil(e.currentTarget.clientHeight) // 50 console.log(Math.ceil(e.cu ...

What could be causing the "incompatible pointer type" error to occur when attempting to pass values in an array?

I am encountering an error/warning while attempting to retrieve the maximum/minimum values from the points in the main function. How can I go about calculating these max/min points? Is there a simpler method available or should I utilize a structure? vo ...

Altering the hue of various stroke patterns

I've encountered an issue where I want to create skill bars that display my skills in percentages. Luckily, I found a great code that allows me to do this. Although I would prefer to do it myself, I haven't come across a good tutorial that teache ...

Issue with the useState hook not correctly updating a value

I'm a beginner in the world of react and I'm puzzled by why the title inside the h1 tag updates, but the url within the Image Component remains unchanged? Component Overview import React, { useState, useEffect, useContext } from 'react' ...

Node.js JSON parser encountering an unexpected undefined error

Whenever I attempt to JSON.parse the string, an error occurs and I receive this message: undefined:1 {"device":"FaclonTest","data":[{"tag":"LATITUDE","value":1903.5091},{"tag":"LONGITUDE","value":07251.0348}]} I'm unsure of where the mistake is. Can ...

Using JQuery to switch out images that do not have an ID or class assigned

Currently, I am using a Google Chrome Extension to apply an external theme to a website. Unfortunately, the logo on the site does not have an ID or class that can be used to call it. I am searching for a solution to replace it with a different image. My ...

The continuous progression of code execution

Having a background in Java, I decided to dive into learning Angular2 recently and have been working on it. However, I encountered a confusing situation in one of my projects that I could not figure out. For the pagination feature I was implementing, I ne ...