Clear the form when add to cart
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 05:21 PM
I'm attempting to clear a form when the user clicks "Add to Cart".
I found this
Which lead to this
I attempted to put the following code in a Client Script with no luck. Any advice on how to get this to work?
function onLoad(){
document.getElementById('add_to_cart_button').addEventListener("click", function(){
reloadWindow(window);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 08:54 PM - edited 12-05-2024 08:58 PM
Hello @rp1
Try with the below Script:
function onLoad() {
document.getElementById('add_to_cart_button').addEventListener("click", function() {
// Reload the window
location.reload(true);
});
}
window.addEventListener('load', onLoad);
Please Mark Correct ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.
Regards,
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:08 AM - edited 12-06-2024 05:43 AM
Still not working. I'm opening a developer instance on the off chance it's something with our instance that is preventing the code from working.
edit - doesn't work in developer instance either....
Console displays the following error -
running Client Script "Clear Form": TypeError: Cannot read properties of null (reading 'addEventListener')
which makes sense because it's null on load because nothing has been done yet.