Error encountered in ASP page due to JavaScript syntax issue

    <script type="text/javascript">
            /* <![CDATA[ */
            var on_id = 1;

     if (<%=GetValue() %>) {
                on_id  = <%=GetValue() %>; 
            }
   </script>

I am encountering two syntax errors: one at the second closed bracket following %>, and another at the semicolon after %>. The GetValue() function is a public method that returns a decimal value, defined in the code behind.

Can someone provide guidance on resolving these issues?

Answer №1

While I may not be a professional, I encountered a similar issue before. The solution came when I placed <%=GetValue() %> within single quotes like this: '<%=GetValue() %>'. Doing so prevented any further syntax errors.

You can utilize the parseFloat() function to extract the float value from a string.

Answer №2

 $.ajax({
      type: "POST",
      url: 'yoururl/RetrieveData',
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
     success: handleSuccess,
    error: handleError
    });

Make an AJAX request and don't forget to check the condition in the success handler :)

Answer №3

Give this a shot


   <script type="text/javascript>
        var identifier = 1;
        <%if (fetchValue()) {%>
            identifier = '<%=fetchValue() %>';
        <%}%>
    </script>

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 best way to run two JavaScript functions simultaneously?

Is there a way to run multiple JavaScript AJAX functions concurrently? ...

Using Typescript to Declare Function and React Component Types

Currently challenging myself to delve into Typescript (ugh). Usually, I can deduce the appropriate type by analyzing the return values. Nonetheless, in this particular scenario, that method is proving ineffective. type SomeReactAProps = { Type1: ReactEle ...

Incorporate a dialogue box utilizing jQuery with dynamically created HTML elements using jQuery

Is it possible to add a jQuery dialog using a string containing HTML code stored in a variable? I have tried out some code, and you can view it here. $("#remove-post").dialog({ autoOpen: false, height: 'auto', width: 'auto&a ...

What is the best way to set up Storybook.js Webpack to support absolute image paths within CSS modules for a Next.js project?

I'm currently setting up Storybook to integrate with Next.js, Ant Design, Less, and TypeScript. In Next.js, images need to be stored in the public/ directory and linked using absolute paths for universal usage within the project. I am facing challenge ...

Refreshing Dropotron Data with jQuery

I'm struggling to find a solution for refreshing the <ul> and <li> elements after the page has already loaded. My <li> element is updated with Ajax data, but despite using jQuery to manipulate the DOM, the changes are not reflected ...

Suggestions for efficiently filtering nested objects with multiple levels in RXJS within an Angular environment?

Just a Quick Query: Excuse me, I am new to Typescipt & RxJS. I have this JSON data: [ { "ID": "", "UEN": "", "Name": "", "Address": "", "Telephone&quo ...

`HTTP Streaming with Axios in a Node JS Environment`

I am currently facing an issue while attempting to stream price data via HTTP (I'm surprised they aren't using websockets..). I usually use axios for making REST API requests, however, I am struggling to handle 'Transfer Encoding': &apo ...

Querying MongoDB to retrieve particular elements from an array within a collection

Results collection contains the following data. _id "9FK5k755ueAYdfip3" createdAt Date {Sat Mar 12 2016 19:58:46 GMT+0100 (CET)} results [Object { errorId="uX6byeiuGjRNXTj6s", error="02/09/15 13:01:29 backu...ox fil ...

Display a block by using the focus() method

My objective is : To display a popin when the user clicks on a button To hide the popin when the user clicks elsewhere I previously implemented this solution successfully: Use jQuery to hide a DIV when the user clicks outside of it However, I wanted to ...

Exception thrown due to exceeding the recursion limit in JavaScriptSerializer

While using the JavaScriptSerializer in my application to serialize an object, I encountered an exception when trying to serialize a collection from the data entity. The code I have is as follows: Fetching records from the database. var data = new Madhu ...

The `this` keyword is incapable of accessing the object. It is instead pointing to the `window` object

Here is a sample of Javascript constructor code: function TestEngine() { this.id='Foo'; } TestEngine.prototype.fooBar = function() { this.id='bar'; return true; } TestEngine.prototype.start = function() { this.fooBar( ...

Search within the XML document for each JavaScript request, and then iterate through another set within the main

I have been developing an Android application using the PhoneGap framework. I created a PHP-XML file to extract data from my website to the application. However, I am facing an issue where I want to display all the <vic></vic> content associate ...

Is there a way to verify if a button on a form has been clicked in an HTML file and then execute a script in Node.js?

As a newcomer to nodejs, I am currently working on one of my goals which involves sending data to a MySQL database based on the information entered into a form. I am seeking assistance on how to execute a function in nodejs when the button on the form is c ...

Pass the extended object from the service to the controller within a promise using the .map function

section: I am currently working on extending a JSON object within a service and passing it to a controller. The JSON originally came to the service from another service that makes backend calls. The code is quite intricate, so I've added comments an ...

You can eliminate the display flex property from the MuiCollapse-wrapper

Having trouble removing the display flex property from the MuiCollapse-wrapper, I did some research and found the rule name for the wrapper in this link https://material-ui.com/api/collapse/ I have been unsuccessful in overwriting the class name wrapper t ...

Display solely the error message contained within the error object when utilizing the fetch API in JavaScript

I am facing an issue in logging the error message to the console while everything else seems to be working fine. Specifically, I am unable to log only the message such as "email exists" when the email already exists in the system. const submitHandler = a ...

The property map of undefined cannot be read

To test my understanding of the map() function, I decided to retrieve data from the Starwars API using the URL: '' and store it in a constant named 'data'. My goal was to only map the characters found in the results[] array, so I creat ...

What is the best way to set a primary key as an array of integers in LINQ?

I am attempting to retrieve values where the main ID, which is an integer, does not match any integers in an array of integers. Below is the code I am currently using: Where(c => !c.CountryId.Equals(model.CampaignCountryIds)) The variable model.Campa ...

Is there a way to simulate holding down a key programmatically in Selenium using C#?

I've been searching for a solution to this issue, but all the resources I found were outdated. The scenario is that I have a flash game on my browser that I want to play using arrow keys programmatically. I already know how to send signals to the key ...

Refresh FullCalendar in Angular 2 and above

Can someone please assist me with re-rendering or redrawing a full-calendar in Angular using @fullcalendar/resource-timeline? I have updated the data after calling the API and now I need to make sure the calendar reflects these changes. Any guidance on h ...