What is the source of this error message "Exceeding maximum characters in string literal"?

Hey everyone!

Sorry for the bother, but I'm a bit stumped on this issue.

Within my view, I have the following code snippet:

<fieldset>
    <dl>
        <dt>
            <label for="FormTypes">Form Type:</label>
        </dt>
        <dd>           
            <% =Html.DropDownList("FormTypes", "All") %>
        </dd>
    </dl>
</fieldset>
<fieldset>
    <dl>
        <dt>
            <label for="Parts">Form Part:</label>
        </dt>
        <dd>           
            <% =Html.DropDownList("Parts", "All") %>
        </dd>
    </dl>
</fieldset>

Everything seems fine, until I add this script at the top to update parts based on form type selection:

<script type="text/javascript">
    <!--
        $('#FormTypes').change(function() {
            var val = $(this).val();
            $parts = $('#Parts');
            $.ajax({
                url: '<%= Url.Action('FormParts') %>',
                dataType: 'json',
                data: { ID: val },
                success: function(parts) {
                    $.each(parts, function(i, part) {
                        $parts.append('option value="' + part.ID+ '">' + part.Code + '</option>');
                    });
                },
                error: function() {
                    alert('Failed to retrieve parts list.');
                }
            });
        });

    //-->
</script>

(the FormParts action returns an object to populate parts dropdown)

An error message pops up saying: Too many characters in character literal on this line:

<% =Html.DropDownList("Types") %>

Seems like adding the javascript triggered this issue. Any thoughts on why it's happening?

Thanks a bunch for any help.

Answer №1

Though the line you extracted is fine, I do have a concern about this section from the original coding:

<%= Url.Action('FormParts') %>

In ASP, using single quotes indicates a character literal rather than a string. To rectify this, simply switch to double quotes like so:

<%= Url.Action("FormParts") %>

Answer №2

The source of the issue was unclear to me initially, but after making some changes to the script, it now functions correctly.

<script type="text/javascript">
    <!--

    $(function() {
        $('#FormTypes').change(function() {
            //clear all items in list and replace "All" option
            $parts = $('#FormParts');
            $parts.html("");
            $parts.append('<option value="">All</option>');

            var selectedValue = $(this).val();
            if (selectedValue != "") {
                $.ajax({
                    url: '<%= Url.Action("FormParts") %>',
                    dataType: 'json',
                    data: { FormTypeID: selectedValue },
                    success: function(parts) {
                        //repopulate list with JSON objects
                        $.each(parts, function(i, part) {
                            $parts.append('<option value="' + part.ID + '">' + part.Code + '</option>');
                        });
                    },
                    error: function() {
                        alert('Parts list could not be retreived. \n Please use the feedback link to inform us');
                    }
                });
            }
        });
    });
    //-->
</script>

For future reference, added a conditional statement to check for the selection of "All" in the first FormTypes dropdown list:

if (selectedValue != "")

This condition ensures that no dependent part list is populated when the "All" option is chosen.

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 post method in $setup is not defined in Vue Composition API

Dealing with a frustrating issue in my Vue application. One page is functioning perfectly fine, while the other is causing trouble by displaying this error: The first page loads a collection of wordpress posts (Blog.vue) without any issues, but the second ...

Apologies, but it seems there was an issue reading the "checked" property as it is null

I am currently facing an issue with the submit button in my Django application. It appears that the Javascript function is unable to determine which checkboxes are checked, as all I see in the console logs are "cannot read properties of null, reading "chec ...

Determine the number of elements chosen within a complex JSON structure

I need to figure out how to count the length of a jsonArray, but I'm stuck. Here's an example to start with: https://jsfiddle.net/vuqcopm7/13/ In summary, if you click on an item in the list, such as "asd1", it will create an input text every t ...

AngularJS - A pagination demonstration incorporating intelligent logic inspired by Google's approach

I struggled to implement a paging solution that I came across online. The issue seems to be related to the timing of function calls, specifically how the setPage function is triggered before all data is retrieved, causing it to not properly determine the t ...

Encountering a problem with ng-repeat when working with a JSON

Having a bit of trouble displaying the keys and values from a JSON object in an HTML table using ng-repeat. The JSON object is coming from the backend, but for some reason, it's not showing up on the frontend. I know there must be a simple mistake som ...

Error: stripe.redirectToCheckout does not exist and cannot be executed

Can anyone help me with implementing Stripe checkout for a website? I've been struggling because the Stripe documentation is incomplete. Here's what I have so far: import React from 'react'; import { loadStripe } from '@stripe/stri ...

javascriptchange the format from <string, string[]> to <string, string>

In my code, I came across a JavaScript object that consists of key/value pairs. Each value in this object is an array of strings: var errors = { "Message": ["Error #1", "Error #2"], "Email": ["Error #3", "Error #4"] }; My goal is to transform thi ...

Retrieving information from an API and transferring it to the state in a React component

I am currently working on a random quote generator project, and I'm facing some difficulties in passing the API data to my state and also accessing it in the QuoteComponent through props. Despite following all the correct procedures, whenever I try to ...

Troubleshooting Problem with Angular JS Ng-Repeat

I have a specific situation where I want to showcase the elements that exist in only one array. If an element is also present in another array, there is no need to display it. My HTML structure looks like this: <div ng-repeat="array1Value in array1"&g ...

What is the best way to extract the value of a string before a comma in Javascript?

I have a challenge where I need to eliminate the city from a city, state combination. For example, if I have the string "Portland, OR", I want to extract only "Portland". Can someone help me with a Javascript solution or guide me on how to achieve this usi ...

The for loop unexpectedly interrupts a different array

Hey there, I've been working with puppeteer and came across an issue with the following code snippet: console.log(dealsId[i]); for (var i = 0; i < sizes.length; i++) { var refIdClasses = await sizes[i].$eval('input', a => a.getAtt ...

Overriding the Ajax URL

During an AJAX request in a Rails app triggered by onchange event, I am encountering an issue with the URL being called. The function for the request is a simple PUT operation: function quantityChange(id, val) { $.ajax({ url: 'cart_items/ ...

When trying to run the "npm start" command, I encountered a syntax error that specifically mentioned the use of

Every time I attempt to run the npm start command, I encounter the following error: I have followed the steps provided in this link: https://github.com/kriasoft/react-starter-kit/blob/master/docs/getting-started.md Could you please advise on how to resolve ...

Using redux alongside fela and react: A comprehensive guide

First of all, thank you for your attention. I am currently exploring the use of fela for dynamically styling my components and for managing app states, I plan to incorporate redux. In fela, it's necessary to utilize a Provider to encompass all app com ...

The magic of coding is in the combination of Javascript

My goal is to create a CSS animation using jQuery where I add a class with a transition of 0s to change the color, and then promptly remove that class so it gradually returns to its original color (with the original transition of 2s). The code below illus ...

Revising Your Task Checklist with React

I encountered an issue while attempting to update the value retrieved from Addlist. Unfortunately, my solution isn't working as expected. Additionally, clicking on the '+' button without entering any text results in an empty list being creat ...

The POST request to the localhost API endpoint resulted in a 404 Not Found error

Whenever I try to send a POST request to "/api/auth/signup" in my JavaScript application, I keep getting a 404 Not Found error. My goal is to create a MERN application for a Modern Real Estate Marketplace. This is the code snippet causing the is ...

Show the current Date and Time dynamically using only one line of JavaScript code

After running this command, I encountered an issue: $("#dateTime").text(new Date().toLocaleString()); The result displayed was 2/21/2020, 10:29:14 AM To make the time increase every second, I attempted this code: setInterval($("#dateTime").text(new Dat ...

Are Twitter Bootstrap buttons compatible with iPad devices?

Have you ever tried using the attractive buttons provided by Twitter? They can be a great alternative to standard radio/checkbox options. If you have used them in your production, how effective were they? I am particularly curious about their compatibilit ...

Enhance the functionality of selectize.js by incorporating select options through ajax

I'm currently working on implementing options to a select box using AJAX and selectize.js. When not using selectize.js, everything functions correctly. The two select boxes are interconnected so that when one is updated, the values in the other select ...