`Is there a way to transfer a GUID from a View to JavaScript?`

I need to pass a GUID as a parameter from a View to a JavaScript function. However, I encountered an error message in Firefox stating "identifier starts immediately after numeric literal."

Below is the code snippet from the View:

onchange="updateOrder(<%= Model.Category[j].OrderItems[i].OrderID %>, <%= Model.Category[j].OrderItems[i].ID %>, this.value, <%= Model.CategoryItems[j].OrderItems[i].Order.JournalID %>);" />

<%= Model.CategoryItems[j].OrderItems[i].Order.JournalID %> is formatted as a GUID.

And here is the corresponding JavaScript code:

function updateOrder(orderID, itemID, quantity, journalId) {
    ... 
}

Your assistance with this issue would be greatly appreciated.

Answer №1

Adding quotes could be beneficial in this situation:

onchange="updateData('<%= Model.Category[j].OrderItems[i].OrderID %>', '<%= Model.Category[j].OrderItems[i].ID %>', this.value, '<%= Model.CategoryItems[j].OrderItems[i].Order.JournalID %>');" />

It's important to note that if the ID values have a possibility of containing a quote character, it will need to be escaped. (Assuming all IDs are in string format like GUIDs. If any are numeric, you can exclude the quotes.)

Answer №2

Give it a shot

onchange="updateOrder(<%= Model.Category[j].OrderItems[i].OrderID %>,
 <%= Model.Category[j].OrderItems[i].ID %>, this.value, 
'<%= Model.CategoryItems[j].OrderItems[i].Order.JournalID %>');" />

Take note of the single quotes around the JournalID parameter

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

The jQuery focusout event is triggered on a form element, even if a child element is clicked within the form

How can I ensure that the focusout event is triggered only when the user is not focusing on the entire form element? Currently, if the user clicks on any of the form's inner elements such as the text field or the button, the event is still being trigg ...

Access a specific element within an array using Handlebars.js

After converting a CSV to JSON, I have data that looks like this: [["Year","Make","Model","Description","Price"],["1997","Ford","E350","ac, abs, moon","3000.00"],["1999","Chevy","Venture \"Extended Edition\"","","4900.00"],["1999","Chevy","Ventu ...

Click to stay in the background

I am currently facing an issue where opening a new tab on click redirects the focus to the child window instead of staying in the current window. I would like the popup to open without blocking and allowing me to maintain focus on my current window. The c ...

Executing a JavaScript code in a Python webdriver: A step-by-step guide

Using Selenium 2 Python webdriver: I encountered an issue where I needed to click on a hidden element due to a hover effect. In search of solutions to unhide and select the element, I came across the following examples: Example in Java: JavascriptExecut ...

Why do I keep encountering a null window object issue while using my iPhone?

Hey there! I've got a React game and whenever the user loses, a new window pops up. const lossWindow = window.open( "", "", "width=500, height=300, top=200, left = 200" ); lossWindow.document.write( & ...

Using the jQuery before() method to manipulate form fields

Is it possible to utilize the jQuery before method to insert a form? An example scenario could be as shown below: <script> $(document).ready(function() { $("button").click(function() { $("button").before('<form><input type="text ...

Testing the functionality of an Angular service using unit tests

Confused about how to test a service in an Angular project that involves a small class with an observer? Can't seem to figure out why the test fails when calling the 'pop' method. Want to ensure that the public methods of this class perform ...

Tips for effectively invoking an MVC Controller using AJAX

I am currently working on initiating an AJAX call to a controller ActionResult within the MVC framework. While I have experience with AJAX, I am relatively new to MVC. I have set up an AJAX call in a separate .js file that is triggered by a button click ev ...

Ensuring that a service is completely initialized before Angular injects it into the system

When Angular starts, my service fetches documents and stores them in a Map<string, Document>. I use the HttpClient to retrieve these documents. Is there a way to postpone the creation of the service until all the documents have been fetched? In ot ...

Protractor test freezes after attempting to click on an element

I have encountered a challenge while attempting to write a protractor test that selects an item from a custom dropdown menu. The issue arises when trying to click on an element other than the last one in the list, as it hangs and times out. Interestingly, ...

Updating a Parent component from a Child component in React (Functional Components)

My functional component RoomManagement initiates the fetchRooms function on the first render, setting state variables with data from a database. I then pass setLoading and fetchRooms to a child component called RoomManagementModal. The issue arises when t ...

Utilize filters on a dataset to display specific information

Front-end: const [filters, setFilters] = useState({ type: "", country:"", }); const onChangeFilterType = e => { const workingObject = {...filters}; workingObject.type = e.target.value; setFilters(workingObject); }; ...

What methods are available to incorporate arithmetic when defining a style attribute?

Is there a way to achieve arithmetic operations in CSS, like calculating margin-left: -60px + 50% of the width of the parent div? I'm eager to find a solution, whether it involves JavaScript or any other method. Any help would be greatly appreciated. ...

I need to loop through an array of ids and add a new mongodb document for any ids that are missing. What is the best way to ensure that they are saved permanently?

Currently, I am utilizing Node JS and MongoDB to manage a collection of documents containing IDs ranging from 1 to 5000. Nevertheless, there are certain IDs that are absent, and I would like each document to be assigned one unique ID. Below is the snippet ...

In JavaScript, you can verify whether the content or blank space of an element was clicked

Is it possible to determine if the clicked part of an element is text or white space? https://i.sstatic.net/0pFgB.jpg My attempts so far have been unsuccessful: body.addEventListener('contextmenu', (e) => { e.preventDefault(); // Prevent ...

The Selenium page_source method does not provide access to any changes made to the DOM tree

I am trying to analyze the impact of using addons like NoScript and Ghostery on a specific webpage. These addons are designed to block trackers' and advertisers' scripts, removing them from the DOM tree. For example, I tested the addon on a scrip ...

Tips for optimizing AJAX content for Google indexing

As I begin the process of developing a public website that utilizes client-side rendering with AngularJS, I have come across information suggesting that dynamically generated content may not be properly indexed by Google. This raises concerns about the imp ...

The Facebook SDK fails to activate in Internet Explorer

I am currently working on implementing a Facebook login using the JavaScript SDK. Everything is functioning correctly in most browsers, but I am experiencing issues with certain versions of Internet Explorer. The login functionality is not working on my l ...

Automatically choose radio buttons within an li element in a loop

Hey there, I'm new to SO and this is my first question. As a bit of a newbie, I found this jquery code snippet on another SO answer that I want to use. The function I'm aiming for is the same, but the markup structure in my HTML is different bec ...

When used simultaneously, two jQuery functions fail to operate as expected

Currently in the process of coding my portfolio, I encountered an issue with incorporating two JavaScript/jquery codes together. Firstly, for the first section to be a full-page scroll using fullpage.js "plugin," and secondly, changing the navbar to be tra ...