Guide on providing a secondary parameter to a JavaScript function

I am currently working on a JSP that contains a JavaScript function:

function validateSelection(identifier, page) {
   var form = ObjectId("profileForm");
   form.elements['checkedLogin'].value = "" + identifier;
   form.elements['pageList'].value = "" + page;
   form.method.value = '<bean:message key="button.valid"/>';
   window.location = "/STFPresentation/admin/userProfileSearch.do?method="
        + form.method.value + "&name=" + identifier + "&pageNum=" + page;
}

The function was functioning properly but I wanted to add a second parameter called "page". The variable "page" is also present in my JSP.

I trigger the JavaScript function by clicking on a link like this:

<a href="javascript:validateSelection('<core:out value="${item.name}"/>', '<%=page_number%>')"><core:out value="${item.name}" /></a>

However, upon clicking, nothing seems to happen. Where did I go wrong?

Thank you for your assistance!

Answer №1

If you encounter issues, consider adding some escapes:

Give this a shot:

<a href="javascript:validateSelection('<core:out value=\'${item.name}\'/>', '<%=page_number%>')"><core:out value="${item.name}" /></a>

By not utilizing escapes, there's a possibility of generating an incorrect series of open and close quotes.

Answer №2

After much troubleshooting, I was able to solve the issue by including a concealed value that includes my page number

Your assistance is greatly appreciated

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

Error: The geoNear command was unsuccessful due to the presence of multiple 2d indexes

My goal is to fetch documents from a collection based on distance. I attempted to utilize the $geoNear aggregation, but encountered errors (while using node.js and Postman) or received zero records as output. Example Document: { "_id" : ObjectId("5cc ...

Working with Variables in JavaScript and PHP Scripting Languages

I have a PHP script that displays all the folders (categories) on my website: echo "<ul>"; foreach(glob('category/*', GLOB_ONLYDIR) as $dir) { $dir = str_replace('category/', '', $dir); echo '& ...

Encountering a CORS Policy Blockage Issue When Using JSON Data, but Resolving it by Changing the Header Type

I created a basic input form that updates data when information is added to it. After following a tutorial, I noticed they used application/json in the header for rendering json data within the input fields. let url = 'http://local ...

Guide to interpreting an Angular expression using traditional JavaScript conventions

I have encountered an issue with the Angular app that I am currently working on. It needs to retrieve the Google Analytics ID from Angular in order to pass it to ga('create', 'UA-XXXXX-Y') using standard JavaScript in my index.html. &l ...

Finding the perfect regex pattern to extract bank transaction information

My goal is to automate the process of reading and extracting information from my monthly bank document that contains all transactions. Currently, I manually input all transactions into an Excel spreadsheet, but I would like to streamline this task. This af ...

A guide to entering information into an input field with JavaScript for logging in successfully

https://i.stack.imgur.com/TF51Z.gif https://i.stack.imgur.com/HHsax.png https://i.stack.imgur.com/HUztt.png When attempting to input text using document.getelement('').value="" , it doesn't behave as expected. The text disappear ...

Setting the root route in express.js is a simple process that involves defining the

As a newcomer to express.js, I'm facing a challenge that has been puzzling me for almost 4 hours. My express server is meant to serve a build of a react app. To determine whether the user is not a bot, I am utilizing the useragent library. The code ...

Create an excel spreadsheet using HTML tables with the help of jQuery

Upon clicking a button, I aim to generate an excel sheet. Essentially, I am trying to achieve what is being discussed here (Kalle H. Väravas answer). If the following links are not working within Mozilla browser, then maybe my code requires ActiveXObject ...

Can you modify a attribute value in one HTML file from another?

I currently have a website and I am looking to modify the aria-expanded value of an expandable paragraph on another page when I click on an anchor element in the main page. What changes do I need to make in my main.html file in order to update the aria-exp ...

empty responseText from GET request using AJAX

I've been working on a chatbox using AJAX and I've encountered an issue where my xhttp.responseText is coming back empty. In firebug, I can see that the GET request is being sent and the correct text is being returned, but for some reason it&apos ...

How to transform a nested string into a JSON object using JavaScript

I am trying to manipulate a nested query string in JavaScript. The string looks like this: var str = "( ( Sentence starts with any of null AND Sentence starts with any of null ) AND Sentence starts with any of null )" I want to split the string at the &a ...

What steps can I take to address the problem in iOS 17 where sound is coming from the earpiece instead of the speaker during camera activation?

I have a Progressive Web App where I use the getUserMedia() API to access the camera and HTML audio tags for handling media content. However, ever since updating to iOS 17, I've faced an issue where audio plays through the earpiece instead of the medi ...

CSS and JavaScript Nav Menu Collapse (No Bootstrap)

I have written a navbar code using pure HTML/SASS, but I am facing a challenge in adding a collapse element to the navigation bar. Despite trying various solutions from Stack Overflow, I still haven't found one that works for me. Therefore, I am rea ...

How to store lengthy JSON strings in SAP ABAP as variables or literals without extensive formatting restrictions

Is there a way to input lengthy JSON data into ABAP as a string literal without the need for excessive line breaks or formatting? Perhaps enclosing the string in a specific template, or utilizing a method similar to JSON.stringify(..) found in other langua ...

Issue with Vue.js: routes are not found upon page refresh

Here is a basic vue-routing example: const Foo = { template: '<div>foo</div>' } const Bar = { template: '<div>bar</div>' } const routes = [ { path: '/foo', component: Foo }, { path: '/ba ...

Having trouble initializing an array of objects to store data in MongoDB using AngularJS

I am facing an issue while trying to save dynamically created HTML in MongoDB using Mongoose from AngularJS. The problem lies in creating the required object that matches the Mongoose schema I have defined. model code var SegmentSchema = new Schema({ n ...

The settimeout function does not seem to function properly within the context of

Currently, I am facing an issue with implementing block UI for blocking a specific div when a button is clicked. The problem I am encountering is that even though I want the blocked div to be unblocked after a certain delay, it remains permanently blocked ...

Encountered an error while trying to retrieve data from

Having trouble with file uploads to the S3 bucket using @aws-sdk/client-s3 library and encountering errors when uploading files larger than 70kbps: `TypeError: Failed to fetch at FetchHttpHandler.handle (fetch-http-handler.js:56:13) at PutObjectCommand ...

Changing the mouse cursor dynamically with Angular programming

What is the recommended approach for changing the mouse cursor programmatically in Angular? For instance: HTML: <div [style.cursor]="cursorStyle">Content goes here</div> or <div [ngStyle]="{ 'cursor': cursorStyle ...

Error: Validation error encountered while validating recipe: _listId field is mandatory and must be provided

As a newcomer to node.js, I am attempting to create a cookbook restful API using nodejs. The goal is to have a list of recipes where each recipe is associated with a specific list selected by its id. However, I am encountering an issue while trying to retr ...