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.
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.
<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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.