What is the best way to establish a conditional statement that ensures ajax fetches the correct XML document?

I am trying to create a dynamic code that fetches an XML file and displays it as a drop-down list based on a condition. If the condition matches study1, then the code should select ctc3.xml; otherwise, it should choose ctc5.xml.

Previously, my code was working fine when fetching a specific XML file, but now I am facing issues with implementing the conditional logic.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script lang="Javascript"> $.noConflict(); 
jQuery(document).ready(function($) {
    var myField = $("#myList") var myOutputField = $("#myOutput").parent().parent().find("input");
    myOutputField.attr("readonly",true);
    var studyID="${studyName}";
    if (studyID!="Test"){
    $.ajax({ 
        type: "GET", 
        url: "includes/ctcae3.xml", 
        dataType: "xml", 
        success: parseXML 
    });
    }
    else {
        $.ajax({ 
            type: "GET", 
            url: "includes/ctcae5.xml", 
            dataType: "xml", 
            success: parseXML 
        });
    }
    function parseXML(xml){
        $(xml).find("atccode").each(function(){
            myField.append($("<option />").val($(this).attr("code")).text($(this).find("description").text()));
        }); 
        myField.val(myOutputField.val());
    } 
    myField.change(function(){
        myOutputField.val(myField.val());
        myOutputField.change();
    });
 });
 </script><select id="myList"> <option val="None"/>None </select> `

Answer №1

The issue has been successfully resolved. It appears that my mind was already exhausted. The solution turned out to be as simple as adding a semicolon ';' to the line var myField = $("#myList");

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

Menu button is expanded without the need to click

The Bootstrap 5 button extends the default behavior and does not collapse. Here is the code: <nav id="header-nav" class="navbar navbar-expand-lg navbar-light"> <div class="container"> <a class= ...

Utilize JavaScript to trigger a function depending on the selected options from dropdown menus

I've been working on a fun little project for a web page where users can select two items from a drop-down menu and then click a button to play a sound corresponding to their selections. However, I'm facing some challenges with getting my JavaScr ...

How can I capture a screenshot of the div displaying pictures uploaded by the user on the frontend?

Take a look at this code snippet. It allows users to upload images, move them around, resize, and rotate them once uploaded. $(function() { var inputLocalFont = $("#user_file"); inputLocalFont.change(previewImages); function previewImages() { ...

Interacting with icons using TouchableOpacity and onPress functionality

I am attempting to implement onPress functionality for icons using TouchableOpacity. However, when I click on the icon, nothing happens and there are no console logs displayed. I have also tried enclosing the icon within an additional View, but that appro ...

Regex search without truncating repetitions

I am trying to locate patterns in strings where a character is followed by another character, and then followed by the first character again. For instance, in the string "abab" I am looking for "aba" and "bab". /([a-z])[a-z]{1}\1/g But when I run t ...

User IDs should not be shown on the jQuery datatable, although they are still accessible

I am wondering if there is a way to display certain user data in a datatable without showing the user id in the table itself. Here is my table: <table id="mitabla" class="display"> <thead> <tr><th>Last Name</th> ...

Randomizing the JSON loop on every page refresh

Having a JSON file containing various data items (as an example) that I am utilizing with handlebars.js to generate templates. The challenge lies in displaying 15 stories (each within their own div) on page load while shuffling their positions upon each r ...

Recording a message from an HTML input using NodeJS and socket.io

I am currently working on a project where I want to log user input from an input box to the NodeJS console. For example, if a user types "Hello world" into the input box and clicks "Send message to console", I want it to show up as "Hello world" in the con ...

How can one transform an array (in the form of a JSON array) into a map?

After running my script, I receive an array (JSON Array) structured like this: [{redirectCount=0, encodedBodySize=60962, unloadEventEnd=0, responseEnd=1601.699999999255, domainLookupEnd=995.7999999896856, ... Now, I want to display the key-value pairs fr ...

webpack - compile one TypeScript file separately (2 actions)

In summary... When my Vue files are combined with background.ts, webpack processes them to create bundled vue files along with background.js I'm unable to run the background.js script I expected background.js to only contain "console.log(' ...

Transform a JSON object into a customized array format with the help of Angular 5 or plain JavaScript

I have a JSON dataset that appears as shown below. [{ {name: "box: 122",x=["2018-01-12T00:01:56.480Z", "2018-01-12T00:05:58.116Z", "2018-01- 12T00:10:00.379Z"], y=[0, 3, 5]}, {name: "box: 125",x=["2018-01-12T00:01:56.480Z", "2018-01-12T00:05:58. ...

Looking to create circular text using HTML, CSS, or JavaScript?

https://i.sstatic.net/pnu0R.png Is there a way to generate curved text in HTML5, CSS3, or JavaScript similar to the image linked above? I've experimented with transform: rotate(45deg); but that just rotates the text without curving it. Additionally, ...

Do not engage with the website while animations are running

I'm working on a JavaScript project where I want to create textareas that grow and center in the window when clicked, and shrink back down when not focused. However, I ran into some issues with the .animate() function that are causing bugs. During QA ...

How to Integrate AngularJS into an HTML Document?

I have a specific goal in mind: to create a single HTML file without separate JavaScript files. While I know that it's possible to include JavaScript inline within HTML, I'm unsure if the same applies to AngularJS. I've attempted to integrat ...

How can I make the background of a button change when I move my cursor over it

Is it possible to change the background image of a button when hovering over it? Perhaps have the image transition from left to right for a fading effect? Can this be accomplished? ...

Tips for creating a hyperlink to a particular tab

Please click here for the demo I am attempting to generate links like this page1.html#section1, page2.html#section2, but these links are not functioning correctly. Relevant code snippet function showSection( sectionID ) { $('div.section'). ...

AngularJS script to dynamically update a table upon selecting an option from the dropdown menu

Just starting out with Angularjs and facing a challenge. I have a table with a "Update" button on the UI and a drop-down option in the 3rd column. The requirement is, upon selecting an option from the drop-down and clicking the "Update" button, the values ...

Extracting array elements in MATLAB based on specific conditions

My matrix, A, is a 4x4. [1 2 3 4; 2 2 2 3; 5 5 5 5; 4 4 4 4] I can easily locate all values less than 4 in A (<4), but I am unsure how to create an 'if' statement that identifies rows with three or more values less than 4. For example, in ...

Exploring the art of reading and writing to a file with JavaScript and NodeJS

I am currently working on creating a function that will scan a file and remove all content below a specific line before adding new lines to the file. So far, I have successfully read the file and identified the target line: function analyze() { lineRe ...

What is the best way to eliminate the "x" close button from the marker's InfoWindow?

How can I eliminate the close button in the marker InfoWindow? [ "Aubrica the Mermaid (nee: Aubry Alexis)", 36.8618, -76.203, 5, "Myke Irving/ Georgia Mason", "USAVE Auto Rental", "Vi ...