document.querySelectorAll('.js-delivery-option').forEach((element)=>{
element.addEventListener('click',function () {
const {productId,deliveryoptionId} = element.dataset;
UpdateDeliverOptions(productId,deliveryoptionId);
checkouotSummary();
});
});
}
checkouotSummary();
When I click the radio I want to update the date but is not happened I will help you the other related code
export function ) {
let deliveroption = '';
deliveryoption.forEach((options) => {
if (options.id === deliverOpoid) {
deliveroption = options;
}
});
return deliveroption || deliveryoption[0];
}
This is deliveoption
export function UpdateDeliverOptions(productId,deliveryoptionId) {
let matchitem;
cart.forEach((item)=>{
if(productId===item.productId){
matchitem=item;
}
});
matchitem.deliveryoptionId=deliveryoptionId;
SaveTostorage();
}
This the update delivery options
This the how I get product
export function getProduct(productId) {
let matchingProduct;
products.forEach((product) => {
if (product.id === productId) {
matchingProduct = product;
}
});
return matchingProduct;
}
Pls help I want when I click the radio the date I want to update the delivery date ${dataString} to get what I click pls
The issue with updating the delivery date on clicking the radio button lies in how thecheckouotSummaryfunction is re-rendering the cart's content whenUpdateDeliverOptionsis called. Here’s a breakdown of the problem and how to fix it:
Problem
When you click a radio button, it triggers theclickevent listener on.js-delivery-option.This callsUpdateDeliverOptionsand thencheckouotSummary()to re-render the entire summary.
This callsUpdateDeliverOptionsand thencheckouotSummary()to re-render the entire summary.
Issue: The re-rendering process resets all dynamic content, including event listeners for the.js-delivery-optionelements.
When you click a radio button, it triggers theclickevent listener on.js-delivery-option.
This callsUpdateDeliverOptionsand thencheckouotSummary()to re-render the entire summary.
This callsUpdateDeliverOptionsand thencheckouotSummary()to re-render the entire summary.
Issue: The re-rendering process resets all dynamic content, including event listeners for the.js-delivery-optionelements.
Solution
We need to ensure that after updating the delivery option, the re-rendered cart correctly reflects the selected delivery date and re-attaches all event listeners.
Reattaching Event Listeners:After updating the inner HTML of the.js-orderSummaryelement, we must reattach theclickevent listeners to the dynamically created.js-delete-linkand.js-delivery-optionelements.
Recursive Re-rendering:WhencheckouotSummaryis called recursively, it dynamically updates the delivery date and other details. The event listeners for radio buttons are re-initialized every time the DOM is updated.
Delivery Option Radio Button Listener:Inside theclickevent listener for.js-delivery-option, we update thedeliveryOptionIdfor the selected product and then callcheckouotSummary()to reflect the changes.
Reattaching Event Listeners:After updating the inner HTML of the.js-orderSummaryelement, we must reattach theclickevent listeners to the dynamically created.js-delete-linkand.js-delivery-optionelements.
Recursive Re-rendering:WhencheckouotSummaryis called recursively, it dynamically updates the delivery date and other details. The event listeners for radio buttons are re-initialized every time the DOM is updated.
Delivery Option Radio Button Listener:Inside theclickevent listener for.js-delivery-option, we update thedeliveryOptionIdfor the selected product and then callcheckouotSummary()to reflect the changes.
Debugging Tips
Console Logging: Addconsole.logstatements in theUpdateDeliverOptionsandcheckouotSummaryfunctions to verify that:The correctproductIdanddeliveryOptionIdare being passed.The cart's content updates as expected.
The correctproductIdanddeliveryOptionIdare being passed.
The cart's content updates as expected.
Check Saved Data: Ensure thatSaveTostorageis correctly persisting the changes.
Console Logging: Addconsole.logstatements in theUpdateDeliverOptionsandcheckouotSummaryfunctions to verify that:
The correctproductIdanddeliveryOptionIdare being passed.
The cart's content updates as expected.
The correctproductIdanddeliveryOptionIdare being passed.
The cart's content updates as expected.
Check Saved Data: Ensure thatSaveTostorageis correctly persisting the changes.
With this implementation, the delivery date will dynamically update when a new delivery option is selected.
Cite this conversation
“import {cart,removerProduct,UpdateDeliverOptions} from '../data/cart.js'; import….” Conversation with ChatGPT (version unspecified), from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84w36f3r3g23xvr508qd9an