I'm having trouble getting "see" in Antigua and Bermuda. I suspect it may be due to the spacing

function ff_CselRegion_action(element, action)
{   
    country = ff_getElementByName('CselCountry');
    state   = ff_getElementByName('CselState');

    var America_NorthArray = new Array('Antigua and Barbuda', 'Canada', 'Greenland', 'USA', 'Mexico');
    if (element.value == 'none') {
        // drop countries
        while (country.options.length > 0)
            country.options[country.options.length-1] = null;
    } else {
        // get the matching array
        var selectedArray = eval(element.value+'Array');

        // drop supernumerous option
        while (selectedArray.length <= country.options.length-1)
            country.options[country.options.length-1] = null;

        // add the new options
        country.options[0] = new Option('Select Country', 'none', true, true);
        for (var i = 0; i < selectedArray.length; i++)
            country.options[i+1] =
                new Option(selectedArray[i], selectedArray[i]);
    } // if

    // drop states
    while (state.options.length > 0)
        state.options[state.options.length-1] = null;
} // ff_CselRegion_action
function ff_CselCountry_action(element, action)
{
    state = ff_getElementByName('CselState');

    var stateArray_Antigua_and_Barbuda = new Array(
    'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul'

    var selectedArray = eval('stateArray_'+element.value);


    if (selectedArray == null) {
        while (state.options.length > 0)
            state.options[(state.options.length - 1)] = null;
    } else {
        // drop supernumerous option
        while (selectedArray.length <= state.options.length-1)
            state.options[state.options.length-1] = null;

        // add the new options
        state.options[0] = new Option('Select State', 'none', true, true);
        for (var i=0; i < selectedArray.length; i++)
            state.options[i+1] = new Option(selectedArray[i], selectedArray[i]);
    } // if
} //ff_CselCountry_action

I am facing an issue with

var stateArray_Antigua_and_Barbuda
because of the spaces causing a problem in identifying 'Antigua and Barbuda' in the var America_NorthArray. As I am relatively new to programming, I would appreciate simple solutions. Thank you beforehand.

P.S. Despite searching online, I have been unable to resolve this.

Answer №1

It is important to avoid including spaces in variable names. A correct format would be

var stateArrayAntigua_and_Barbuda
. If there are no other issues with your code, you should be good to go.

If you want to delve deeper into this topic, I recommend reading this article. Essentially, it is best practice to use latin letters digits, _, and $ in variable names.

Additionally, in the lines:

var stateArrayAntigua and Barbuda = new Array(
    'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul'

You have also encountered a syntax error: the closing bracket is missing.

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 onselect attribute within the HTML <option></option> element allows you to trigger an event when a user selects an

Hello! I'm currently working with a list that has an onChange event within the <select>... tag. In the code snippet below, you can see that there are two options. The option labeled 55-rene has the attribute selected="selected", making it automa ...

What is the best way to ensure that an element remains active even after a page refresh?

I have been using this code to activate the current element, which I came across on a website called "w3schools.com". However, whenever I refresh the page, the currently active element disappears. Is there a way to ensure that the active element remains hi ...

Delete the element that was generated using jQuery

Is there a way to add and remove an overlay element using JavaScript? I am struggling to get JavaScript to remove an element that was created with JavaScript. Any suggestions? Check out this JS Fiddle example Here is the HTML code: <div id="backgroun ...

Transferring a variable from a .jsp file to a .js file

I'm currently working on a .jsp page where the appearance of a different div from a .js file depends on the header that comes from a request. I've added a second header and now want if (info.getLightHeader()!=null) the <div id="lightHeader ...

Firing an event when a user reaches a particular element by scrolling using jQuery

I have a situation where I need to detect when an h1 element is in the user's view on a website... <h1 id="reach-here">FIRE ALERT WHEN REACHED</h1> and my goal is to display an alert message when the user scrolls to and sees the h1 headi ...

Tips for including HTML elements as children within Angular Higher Order Components (HOC)

I am looking to pass an HTML element within my Angular Higher Order Component. Currently, I am passing a child element as an @Input decorator. Here is how my HOC, Main Container, looks like: <div> <p> MY EXTRA UI HERE</p> <ng-contai ...

Is there a way to incorporate an 'input' type within an Icon Button component from Material UI in a React project?

Kindly review my code below. I have revamped it for clarity so you won't need to stress about important details! const test = () => { return ( <label > <input type='file' multiple style={{ display: &ap ...

The latest update to the Server Stats code mistakenly changes the channel to "undefined" instead of displaying the total number

I've been working on a private bot for a specific server that displays server statistics and more. However, I've encountered an issue where every time a user joins or leaves the guild, the bot updates a channel with 'undefined' instead ...

Transforming a hierarchical array into a string based on a specific condition

Seeking assistance in properly formatting data using the reduce method const testData = { a: [1], b: [2, 3, 4], c: [] }; Objective is to convert to: a=1&b=2,3,4 Current output: a=1&b=2,3,4& const createUrlString = params => Object.key ...

Adjust date by one day using the Datetimepicker tool

I have been attempting to adjust the date of my input by one day either forward or backwards, but I seem to be stuck and not making any progress. Take a look at my code: function function backDay() { var date = $('input#datetimepicker').va ...

IntellJ Editor encounters Typescript error

Currently engaged in a project using Angular 1.6 and Typescript. Up until recently, there were no compilation errors to be found. However, I am now encountering some peculiar errors. The code remains unchanged and the application is functioning properly. ...

Changing the context of Selenium using node's wd package

I'm having trouble finding documentation for Java clients, but I did come across the implementation for Node's wd client. However, I can't seem to locate where exactly it is in the module's external API. I'm not even sure what the ...

Guide on embedding .ascx control into .aspx page seamlessly without triggering a postback or refreshing the page

I'm currently working with some code that is functioning well. I'm looking to create a cookie and have the .ascx control load in order to execute a specific function on the cookie without causing the page to post back. What is the best way for me ...

The function 'transformArticles' is not recognized as a property of the object 'Article'

I'm encountering an issue with Typescript that I need help understanding. In my code, I have a route where I am importing a class called Article like this: import { Request, Response } from "express"; const appRoot = require("app-root-path"); import ...

Interactive form found on a webpage

Hey there! I'm currently working on a task where I want a form to be displayed when the edit button is clicked. Once the save button in the form is pressed, I want to update my database with the new information. It's crucial that this process hap ...

Ensure that the Jquery inview element functions both upon initial load and as the user scrolls

I've been working on implementing the inview function by adding and removing a class to an element, but for some reason it's not functioning as expected. Can anyone offer some assistance with this? http://jsfiddle.net/zefjh/ $.fn.isOnScreen = f ...

One can use basic JavaScript or jQuery code for a straightforward solution

I am facing an issue. While I have a good grasp of HTML, CSS, PHP, and design, I lack knowledge in JavaScript and jQuery. There's a simple jQuery function that I need to implement, but I am unsure about how to go about it. The task at hand is to acce ...

ReactJS attempting to invoke a class function using a dynamically generated button

When attempting to access the deletePost(index) method from the ShowPost class using a dynamically rendered button within the render() step in React, I encounter an issue. The button labeled "click me" successfully retrieves and prints the first item in my ...

Steps for transforming Dec 2 1991 12:00AM into 12/02/1991

const dobString = "Dec 02 1991 12:00"; const newDate = dobString.substring(0, dobString.length - 6); const birthDate = $filter('date')(new Date(newDate), 'mm/dd/yyyy'); ...

Stop the page from unloading before the ajax request is made

Seeking a solution similar to this question: Reliably complete Ajax request on page unload I am in need of triggering a network request before the page closes without requiring the response value. However, simply placing it within my beforeunload handler ...