The function of slidetoggle is malfunctioning when clicked

I currently have two dynamic containers with one displaying grouped boxes, quantities, and totals, while the other shows detailed information.

Both container values are added dynamically at runtime. By default, the grouping container is displayed on the page.

The values are fetched using jQuery to showcase them in a "preview" table located outside the div containers.

I am attempting to utilize slidetoggle functionality to switch between the containers upon clicking a link, which works smoothly. However, I am encountering issues with the table as the values appear incorrect initially and upon subsequent clicks of the link.

For reference, you can view my current jQuery script here: [My jsfiddle][1]

Below is the test markup:

<div class="ToogleGroupContainer">
<div class="shipToSingleSection">
    <div class="shoppingCart_Category">
        <div class="shoppingCart_Box">Box#01</div>
        <div class="shoppingCart_qtyArea">
            <div class="shoppingCart_qtyLabel">QTY</div>
            <div class="shoppingCart_qty-select">5</div>
        </div>
        <div class="shoppingCart_Price_Each">Each 26.99</div>
        <div class="shoppingCart_SubTotal_Each">Price 134.95</div>                
    </div>
    <hr />
</div>
<div class="shipToMultipleSection" style="display:none;">
    <div class="shoppingCart_Category">
        <div class="shoppingCart_Box">Box#01</div>
        <div class="shoppingCart_qtyArea">
            <div class="shoppingCart_qtyLabel">QTY</div>
            <div class="shoppingCart_qty-select">1</div>
            <div class="shoppingCart_qty-select">1</div>
            <div class="shoppingCart_qty-select">1</div>
            <div class="shoppingCart_qty-select">1</div>
            <div class="shoppingCart_qty-select">1</div>
        </div>
        <div class="shoppingCart_Price_Each">Each 26.99</div>
        <div class="shoppingCart_SubTotal_Each">Price 26.99</div>

    </div>
    <hr />
</div>
</div>
<table class="tableOrderPreviewTotals" border=1>
<tr>
    <td class="yord_hdr">Item</td>
    <td class="yord_hdr_center">QTY</td>
    <td class="yord_hdr_center">Each</td>
    <td class="yord_hdr_center">Price</td>
</tr>
<tr>
    <td class="yord_line_item" stlye="display:none;">
        <div id="itemOrderPreview"></div></td>
    <td class="yord_line_qty" stlye="display:none;">
        <div id="qtyOrderPreview"></div></td>
    <td class="yord_line_right" stlye="display:none;">
        <div id="priceEachOrderPreview"></div>
    </td>
    <td class="yord_line_right" stlye="display:none;">
        <div id="subtotalEachOrderPreview"></div>
    </td>   
</tr>
</table>

<br/>
<a href="" class="shipToMultipleLink">Ship Order to Multiple Addresses</a>

It's apparent that there are inconsistencies in the data presentation. The goal is to show values accurately based on which container is active on the page.

The desired default display should be:

Item QTY Each Price

Box#1 5 26.99 134.95

Once the "Ship to multiple addresses" link is clicked (toggled), the table lines should adjust accordingly:

Item QTY Each Price

Box#1 1 26.99 26.99

Box#1 1 26.99 26.99

Box#1 1 26.99 26.99

Box#1 1 26.99 26.99

Box#1 1 26.99 26.99

Upon toggling back to the "Ship to single address" mode, the table line should revert to the default display:

Item QTY Each Price

Box#1 5 26.99 134.95

Any assistance provided will be highly appreciated!

Thank you for your help.

Answer №1

give it a shot

  $(document).ready(function () {
        $('.shipToMultipleLink').click(function () {
            $('.shipToMultipleSection, .shipToSingleSection').slideToggle('fast');
            return false;

        });

            $.each($('.shipToMultipleSection .shoppingCart_qty-select'), function () {
                $("#itemOrderPreview").append($(".shoppingCart_Box").html()).append("<br>")
                $("#qtyOrderPreview").append($(this).html()).append("<br>");

                var each = $('.shoppingCart_Price_Each').html().replace(/Each/,"")
                $("#priceEachOrderPreview").append(each).append("<br>");

                var price = +each * $(this).text()
                 $("#subtotalEachOrderPreview").append(price).append("<br>");
            });

      var h = '<tr class="singleLine" style="display:none;">'
      /* edited */
      h += '<td>' + $(".shoppingCart_Box").html() + '</td>'
      h += '<td>' + $(".shoppingCart_qty-select").html() + '</td>'
      h += '<td>' + $('.shoppingCart_Price_Each').html().replace(/Each/,"") + '</td>'
      h += '<td>' + $('.shoppingCart_SubTotal_Each').html().replace(/Price/,"") + '</td>' 
      h += '</tr>'
      $(".tableOrderPreviewTotals tr:last-child").after(h)

    });

jsfiddle: http://jsfiddle.net/alemarch/k3t0cbcc/4/ is this what you're looking for?

Answer №2

Wow, things are a bit messy here..

Let's start by troubleshooting your jQuery code:

 $('shipToMultipleLink').hide();
 $('shipToSingleLink').show();

This should be corrected to:

 $('.shipToMultipleLink').hide();
 $('.shipToSingleLink').show();

After fixing that, make sure to tidy up the rest of your code and provide a clearer explanation of your issue so we can assist you better.

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

Displaying search results seamlessly on the same page without any need for reloading

I am looking to create a search engine that displays results without the need to refresh the page. I have come across using hash as a potential solution, but I don't have much knowledge about web programming. So far, with the help of tutorials, I have ...

Issue with Cascading Dropdowns in jQuery

I am currently experiencing issues with a piece of code on my website (also accessible via this link). The code consists of 2 select fields that should display different data based on the selection made. However, I have identified 2 bugs within the code. ...

Display a list with a set limit and an option to show more by clicking

I am currently struggling to develop a list of items that displays 3 items per row, and when the "show more" button is clicked, another 3 items should be displayed. My issue arises when using map and slice, as this method results in rendering 3 of the same ...

JQuery script showing no signs of functioning, even though it runs smoothly in the console

I'm looking to create a clickable div for the Nivo slider on this website so visitors can easily navigate to a featured article. To debug the issues, I wrote the following script in Chrome's console: var $j = jQuery.noConflict(); $j(function(){ ...

Animating SVG while scrolling on a one-page website

Is there a way to incorporate SVG animation scrolling in a single page website? I am inspired by websites like and . The first one stands out to me because the animation is controlled by scrollup and scrolldown actions. I haven't written any of my S ...

unable to reset contact form functionality

I need to implement a Contact Us form on my website. The form should clear the text fields after submission and display a Thank You message. Below is the HTML code: <div class="form"> <div id="sendmessage">Your message has been sent. Thank yo ...

Here's a guide on using a button to toggle the display of password value in Angular, allowing users to easily hide

I have successfully implemented an Angular Directive to toggle the visibility of password fields in a form. However, I am facing an issue with updating the text displayed on the button based on the state of the input field. Is there a way for me to dynami ...

What is the best way to customize the appearance of chosen selections in the MUI Autocomplete component?

I'm currently facing an issue with changing the style of selected options in MUI when the multi option is enabled. My goal is to alter the appearance of all highlighted options. Any assistance on this matter would be greatly appreciated, thank you! ...

Combining Turn.js with AJAX for an interactive web experience

I've been experimenting with turn.js and struggling to find an example of loading dynamic pages with content via ajax. While the page is loading, it's not displaying all the results. For a JSON result from the controller, click here. <div clas ...

The issue with Multiselect arises when the array is being set up initially

Using primeng Multiselect, I have implemented a logic to push data based on search value from the backend. To avoid the error of pushing undefined elements, initialization is required before pushing. However, when I initialize the dropdown's array var ...

Icon for local system displayed on browser tab

I am currently trying to set a Browser Tab icon for the local system, but it is not working. However, when using an HTTP static icon, it works perfectly. Can someone please help me understand what the issue might be? PAGE 1 : Icon Not Showing <link re ...

Strategies for resolving type issues in NextJs with Typescript

In my project using Next.js with TypeScript, I encountered an issue while trying to utilize the skipLibCheck = false property for enhanced checking. This additional check caused the build process to break, resulting in the following error: Error info - U ...

Node.js and the Eternal Duo: Forever and Forever-Montior

Currently, I am utilizing forever-monitor to launch a basic HTTP Node Server. However, upon executing the JavaScript code that triggers the forever-monitor scripts, they do not run in the background. As a result, when I end the TTY session, the HTTP server ...

The Facebook JS SDK is causing an XSS error and returning a "user_denied" response, even though the Auth Popup for FB.Login is not being

I currently have a Facebook canvas app located at Previously, I was using an anchor link to direct users to the OAUTH login flow. After implementing the Facebook JavaScript SDK, I followed this logic: 1) Initialization of the FB API FB.init({ a ...

Issue with popup display in React Big Calendar

I'm currently working on a calendar project using React-Big-Calendar, but I've run into an issue with the popup feature not functioning properly. <div className={styles.calendarContainer} style={{ height: "700px" }}> <C ...

Utilizing Express 4, create a fresh route within an app.use middleware

I'm currently working on an express nodejs app where I am attempting to implement "dynamic routes" within another route. Here is what I have: .... app.use('/test/:id', function(req,res,next) { app.use('/foo', sta ...

I encountered an error while trying to deploy my next.js project on Vercel - it seems that the module 'react-icons/Fa' cannot be found, along with

I'm currently in the process of deploying my Next.js TypeScript project on Vercel, but I've encountered an error. Can someone please help me with fixing this bug? Should I try running "npm run build" and then push the changes to GitHub again? Tha ...

Why is it that one of my useQuery hooks is returning a value while the other one is returning undefined?

I'm currently facing an issue with React Query where one of my useQuery hooks is logging undefined while the other one is displaying the correct data. Both functions are async and perform similar tasks. I've been troubleshooting this problem for ...

Angular - a simple method to determine the number of non-empty inputs in a complex template-driven form

As I work on multiple substantial Angular 11 template forms containing basic inputs like text, radiolists, and checkboxes, I am looking for the most effective method to calculate the percentage of completed inputs while the user is actively engaging with ...

Tips for expanding the content of a blogger page to fill the entire frame of the page

Check out this page: . Currently, the video on the page does not fill up the entire screen. Any suggestions for a solution? ...