Trouble handling Ajax response

I have two JSP files described below.

The parent JSP page contains a Select dropdown box with two options.

Another JSP file, dispTable.jsp, displays select boxes inside a table.

If the user selects "one" from the dropdown in the parent.jsp page, I want to display the output of dispTable.jsp using AJAX response in the parent.jsp page.

The issue I'm encountering is that while the content of dispTable.jsp is displayed in parent.jsp as an AJAX response, the '>>' and '<<' buttons do not function.

However, if I directly execute dispTable.jsp by providing the parameter and value in the URL, the select tables and buttons work perfectly.

Why does the same output not work for parent.jsp?

For the following URL, the output works perfectly:

 **parent.jsp**
<!-- HTML and Javascript code here -->

Answer №1

Ensure that the Javascript code is not duplicated in both the "parent" and "dispTable" - it should be removed from one of them.

Take a look at functions like GetSelectValues(CONTROL) and FillListValues(CONTROL).

Just a tip - you can write something similar without using the "buffer".

....

It's worth noting that I used "one".equals(name) instead of name.equals("one") as it also handles null cases. Please inform me if there is anything else you require that might have been overlooked.

Below is my functional code (I had to remove the 'one'.equals condition in my workspace due to lack of JSP support)

The parent file appears as follows:

<html>
      <head>
      <script language="javascript" type="text/javascript">
      function showEmp(str){
          $("#emp").load("dispTable.jsp");
      }
      </script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

      </head>
      <body>

      <script type="text/javascript">
          function add()
          {
               return !($('#list1 option:selected').remove().appendTo('#list2') && ($('#list2:last-child').selected="selected"));
          }
          function remove()
          {
               return !$('#list2 option:selected').remove().appendTo('#list1');
          }
</script>

<select name = "ratingsClient" style="width: 150px" id="ratingsClient" onchange="showEmp(this.value)">
<option value="aaa">aaa</option>
<option value="one">one</option>
<option value="two">two</option>
</select>
<br>
      <div id="emp">
      <table name="emp" >

      </table>
      </div>
</body>
</html>

And here is how the "dispTable" file is structured:

<table>
<tr>
<td>
<SELECT class="select" NAME="list1" id="list1" MULTIPLE SIZE=10 style="width:150px;">;
    <option value="co_group">Compnay Description</option>
    <option value="pe_rev_name">Contact Name</option>
    <option value="co_tel_work">Telephone</option>
    <option value="action_flag">Company Address</option>
    <option value="co_group">Compnay Description</option>
    <option value="pe_rev_name">Contact Name</option>
    <option value="co_tel_work">Telephone</option>
    <option value="pe_position">Contact Position</option>
    <option value="pe_tel_work">Contact Telephone</option>
    <option value="ref_no">ISBN</option>
</SELECT>
</td>
    <td>
        <INPUT TYPE="button" NAME="right" VALUE="&gt;&gt;" id="add" onclick="add()" style="width:40px;"><BR><BR>
        <INPUT TYPE="button" NAME="left" VALUE="&lt;&lt;" id="remove" onclick="remove()" style="width:40px;"><BR><BR>
    </td>
    <td>
        <SELECT NAME="list2" id="list2" MULTIPLE SIZE=10 style="width:150px;">
        </SELECT>
    </td>
</tr>
</table>

UPDATE: Expanding on the response to demonstrate how to send the "value" of the select box in the ajax request using the "GET" method instead of "LOAD"

function showEmp(str){
    $.get("dispTable.jsp",{"count":str},function(result){$("#emp").html(result)})
}

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 dynamically add a stylesheet using JavaScript/jQuery?

I've been scouring the web for a solution to a particular issue, but so far I'm coming up empty-handed. We're working with Umbraco CMS for a client's website, and it seems we can't insert conditional comments in the <head> se ...

jquery monitors an element to see if it contains a particular attribute, then takes action accordingly

I'm attempting to conceal a div when an anchor tag (a) has a particular href, and reveal it when the href is different. This is what I've tried: if($('a[href="#intro"]').not(".active")) { $('.navbar-brand').hide();} else ...

Discover the method for converting a local file into a string

Looking to retrieve and read an SVG file in Angular 6 from the assets folder as a string. I've attempted the following: this._htmlClient.get('../../assets/images/chart1.svg').subscribe(data => { console.log('svg-file: ', ...

Receiving a "Maximum call exceeded" error when using Vue.js router guards for the beforeEach hook

As I work on my Firebase-VueJS app, I am implementing basic security rules with router guards. In my main.js file, I have added the following code to handle permissions based on the user's authentication status. However, I encounter an error 'vue ...

Having trouble with NPM install because of a node-gyp issue?

We're facing issues with running "npm install" on our project. The error message states that a specific file cannot be located: fatal error C1083: Cannot open include file: 'windows.h' This error seems to be originating from the node-gyp mo ...

How can I utilize the parseFloat feature within my dedicated parseFloat function located in an angular factory?

What is the solution for accessing parseFloat within an angular factory function named parseFloat? angular .module('myApp') .factory('mathService', [MathService]); function MathService() { return { parseFloat: myGl ...

Using Vue Router's `push()` method within an asynchronous function will solely modify the URL address

I created a custom loading component that displays while the route is being changed. To ensure the loading component properly waits for a second, the method needs to be asynchronous. However, since implementing this feature, I noticed that the router.push ...

View content from an external file within an iframe

My goal is to showcase a text file within an iframe that updates automatically every second. To achieve this, I have created a simple function: function refresh() { $("#derek").attr('src', $("#derek").attr('src')); }; The automati ...

Generate a graph showcasing the frequency of character occurrences within a specific column of a .csv file

I'm currently working on creating a graph using d3.js What I need to accomplish is reading the some_column column in a .csv file and counting the occurrences of | to plot them accordingly on the y-axis. The line should be plotted based on the number ...

Vue displays error logs within Karma, however, the test failure is not being reflected in the Karma results

Currently, I am in the process of writing unit tests for Vue components within our new project. For testing, I am utilizing Karma with Mocha + Chai, and PhantomJS as the browser. The test command being used is cross-env BABEL_ENV=test karma start client/ ...

When attempting to add or store data in MongoDB, it triggers a 500 server error

Greetings, I am currently working on developing a CRUD app using the MEAN stack. The Express application loads successfully and retrieves the "contactlist" collection from the database. However, when attempting to make a POST request to "/api/contacts", an ...

Generating a multidimensional associative array based on user inputs from a form

What is the best way to transform form input data into a multidimensional associative array? This is how the form appears: <div id="items"> <h4>Engraving Text</h4> <div class="item" data-position="1"> <h4 id="en ...

Monitoring $scope modifications within a directive: A simple guide

I am currently working with a directive that looks like this: app.directive('selectedForm', function(MainService) { return { scope: { formName: '=currentForm' }, restrict: 'E', ...

Can you explain the mechanics behind the animation of the upvote button on steemit.com?

Behold the upvote button of steemit.com: <span class="Icon chevron-up-circle" style="display: inline-block; width: 1.12rem; height: 1.12rem;"> <svg enable-background="new 0 0 33 33" version="1.1" viewBox="0 0 33 33" xml:space="preserve" xmlns=" ...

Angular File Sorting Error in Gulp detected

After including .pipe(angularFilesort()) in my gulp script, the task runs wiredep but never proceeds to the default task. It just stops after executing wiredep. However, if I remove .pipe(angularFilesort()), the script works perfectly fine. Can someone h ...

Adjusting the dimensions of a rectangle using jQuery: A step-by-step guide

I am encountering an issue while attempting to adjust the width and height of a rectangle using jQuery. The error message I receive is "Uncaught TypeError: Cannot read property 'scrollWidth' of null" Below you can find the code snippet in questi ...

Keep sending HTTP requests until the header contains an attachment

Welcome to our web application where you can generate and download a .zip file simply by visiting the URL. I am looking to develop a Node.js application using the requestjs library that will continuously send requests until it detects an attachment header ...

When the update button is clicked, the textfield is hidden; it reappears upon refreshing the page

Our marketplace multi-vendor site on Magento allows sellers to list their products for sale. The frontend displays the price using the following code: Phtml <input onFocus="showPriceCancel('<?php echo $products->getId(); ?>');" clas ...

Exploring FabricJs: Reassessing the coordinates of an object post-rotation

const canvas = new fabric.Canvas("c", { selection: false }); const refRect = new fabric.Rect({ left: 250, top: 150, width: 200, height: 100, fill: 'transparent', stroke: 'blue', originX: 'center', originY: & ...

Guide to setting up a Cordova and TypeScript project using the command line interface

For my mobile application development, I rely on Cordova and execute cordova create MyApp in the command-line to initiate a new project. I am familiar with JavaScript but now require TypeScript for my project. Please assist me in setting up a Cordova pro ...