简体   繁体   English

带有var文档的弹出消息

[英]Pop-up message with var documents

I'm trying to make a form with pop up message where if the user doesn't fill up the input box nothing will happen and I'm done with that using required = "required" of input type number. 我正在尝试制作一个带有弹出消息的表单,其中如果用户不填写输入框,将不会发生任何事情,并且使用输入类型编号的required = "required"来完成此操作。

What I need is when the input box has been filled a message will pop up and says that the item is added when the button is clicked by the user. 我需要的是输入框已填充时,将弹出一条消息,并说用户单击按钮时将添加该项目。

Here's my code: 这是我的代码:

 <label style="color:#000000;">Qty:
 <input type="number" min="1" name="qty" required = "required" />



 SCRIPT:
 <script type="text/javascript">
 function myFunction()
 {
 var a=document.forms["abc"]["qty"].value;
 if (a!=null){
 alert("Item has been successfully added to your Cart");
  }
  }
  </script>




  echo '<td>'.'<input name="but" type="image" value="'.$row3['id'].'"      
  src="images/button.png"  onclick="myFunction()" />'.'</td>';

You have to use an id for your input tag. 您必须为输入标签使用id。

    <label style="color:#000000;">Qty:
 <input type="number" min="1" id="qty" name="qty" required = "required" />



 function myFunction()
 {
 var a=document.forms["abc"]["qty"].value;
    if (a!=null && a!= ""){
     alert("Item has been successfully added to your Cart");
    }
 }

Also check for empty fields 同时检查是否有空字段

您错过了函数myFunction中的形式名称-“ abc”-您通过以下方式调用element

var a=document.forms["abc"]["qty"].value;

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

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