添加购物车按钮上的网页警报消息

时间:2015-10-09 15:15:36

标签: javascript php html shopping-cart

如果未在表单中选择尺寸或颜色单选按钮,我想在我的网页中显示警告消息。有谁能够帮我?我尝试了一些东西,但没有奏效。请参阅下面的代码:

<div id="Form"><form method="POST" autocomplete="off" title="Product">     
  <input name="title" type="hidden" id="title" value="0">
  <br>
  <p name="cor">
    <strong>
    <label><br>Color:</strong></span><br>
    </label>
    <label><input type="radio" name="cor" value="white" id="cor_0">
      White</label></p>
    <p name="Size">
    <label><br>Size:<br></label>
    <label><input type="radio" name="size" value="22" id="22" onclick="setShoppingCartUrl(this)">
      M</label>
    <label><input type="radio" name="size" value="23" id="23"     onclick="setShoppingCartUrl(this)">
      G</label>
    </strong></p>
  <p><br></p>
<script>
 baseurl = 'cart2.php?add=';
function setShoppingCartUrl(e) {
document.getElementById('shoppingcart').href=baseurl+e.value
}
</script></div>
<div><script>
function setShoppingCartindexUrl()
if (value < 20) {
    alert('<?php echo "Please select your size"; ?>');
         }
    else {
    href="cart2.php?add=."
    }   </script>
<a id="shoppingcart" onclick="setShoppingCartindexUrl()" target="_self"><img      src="images/carrinho01.jpg" alt="noiva em detalhes" width="100%" height="100%"       align="rigth" margin-right="8%"/></a>
</div>
</form>

1 个答案:

答案 0 :(得分:0)

经过一些研究后,我确切地建立了我需要的东西,所以在实施后我的代码下面......

<script>
function validateForm() {
var x = document.forms["myForm"]["size"].value;
if (x == null || x == "") {
    alert("Querida cliente, favor selecionar o tamanho desejado antes de adicionar ao carrinho.");
    return false;
}
else {
        href="cart2.php?add=."
    }}
</script>
<a id="shoppingcart" onclick="validateForm()" target="_self"><img src="images/carrinho01.jpg" alt="noiva em detalhes" width="100%" height="100%" align="rigth" margin-right="8%"/></a>