简体   繁体   English

将项目添加到cart.php时的JS弹出消息

[英]JS popup message when adding item to cart.php

I have this line of code: 我有这行代码:

<form name="addtocart" method="post" action="cart.php">
<input type="text" size="3" name="qty" value=""><input type="hidden" name="action" value="add_item"><input type="hidden" name="id" value="<?php echo $record->itemId; ?>"><input type="image" src="../css/images/cart.png" align=absmiddle >
<a href="favorites.php?action=setFavorite&itemnr=<?php echo $record->itemId; ?>"><img src="../css/images/favorite.png" align="absmiddle" alt="Toevoegen aan favorieten" title="Toevoegen aan favorieten" border="0"></a>
</form>

Now I want to display a popup when a item is added to cart.php. 现在,当项目添加到cart.php时,我想显示一个弹出窗口。 I have tried a simple onclick event, this works, but then the item is not added to the cart. 我尝试了一个简单的onclick事件,该方法有效,但是没有将该项目添加到购物车中。 It just displays the popup. 它只是显示弹出窗口。

So I just want something you see on most modern webshops, but I am completely new to JS, so except for onclick I have no more knowledge left on how to get this done. 所以我只想要您在大多数现代网上商店中看到的东西,但是我对JS完全陌生,因此,除了onclick之外,我对如何完成此工作没有更多的了解。 I have google'd for ever, so i thought maybe someone here might give a little tip or example on how to get this done. 我已经永远使用Google,所以我想也许有人在这里提供一些有关如何完成此工作的提示或示例。

Thanks a bunch! 谢谢一群!

Considering your current JS code : 考虑您当前的JS代码:

onclick="window.open('test.php'); return false"

Just remove return false as it prevents the form from being validated. 只需删除return false即可,因为它会阻止表单被验证。 SO 所以

onclick="window.open('test.php');"

Should open the popup, validate the form, and redirect current page to cart.php. 应该打开弹出窗口,验证表单,然后将当前页面重定向到cart.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM