gpt4 book ai didi

javascript - 表单中的警报消息

转载 作者:行者123 更新时间:2023-12-02 18:01:47 24 4
gpt4 key购买 nike

我仍然无法获得正确的流程。我知道这很简单,我认为我的代码是正确的,但当我点击购买按钮时,即使输入框为空,仍然会显示警报消息。我想要的是,如果输入框为空,则不会显示任何警报消息,但如果输入框已填满,那么这是单击按钮时唯一显示警报消息的时间。这是我的代码:

 <?php
require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Athan Motorcycle</title>
<style type="text/css">
<!--
.style1 {
color: #000000;
font-weight: bold;
font-size: 24px;
}
-->
</style>
<!--<script type="text/javascript">
function validateForm()
{
var a=document.forms["abc"]["qty"].value;
if ((a==null || a==""))
{
alert("Please specify the quantity.");
return false;
}
}
</script>-->

</head>
<body>
<form action="saveorder.php" name="abc" method="post">
<input name="id" type="hidden" value="<?php echo $_SESSION['SESS_MEMBER_ID']; ?>" />
<input name="transcode" type="hidden" value="<?php echo $_SESSION['SESS_FIRST_NAME']; ?>" />
<table width="400" border="0" cellpadding="0" cellspacing="0">
<?php
if (isset($_GET['id']))
{


include('config.php');

$id=$_GET['id'];
$result = mysql_query("SELECT * FROM athan_products WHERE product_id = $id and status='available'");
$row3 = mysql_fetch_array($result);
echo '<tr>';
echo '<td width="80"><img alt="Motor" src="images/motor/'.$row3['product_photo'].'" /></td>';
echo '<td width="200"><span class="style1">'.'</span></td>';
echo '<td width="120"></span></td>';
echo '</tr>';
echo '<tr>';
echo '<td width="80"><input name="name" type="text" value="'.$row3['partsname'].'" readonly/><input name="ingre" type="hidden" value="'.$row3['product_ingredients'].'"/> <input name="ids" type="hidden" value="'.$row3['id'].'"/></td>';
echo '<td width="120"></span></td>';
echo '</tr>';
}
?>
</table>
<br />
<label style="color:#000000;">Qty:
<input type="number" min="1" id="qty" name="qty" required = "required" />


</label>
<br />
<table width="400" border="0" cellpadding="0" cellspacing="0" style="color:#000000;">
<tr>

<!--<td width="179">Size</td>-->
<td width="128">Price</td>
<td width="179">Description</td>
<td width="93">Selection</td>
</tr>
<?php
if (isset($_GET['id']))
{


include('config.php');

$id=$_GET['id'];
$result = mysql_query("SELECT * FROM athan_products WHERE product_id = $id");
while($row3 = mysql_fetch_array($result))
{
$resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE '%".$id."%'");
//$resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE =$id");
while($rows = mysql_fetch_array($resultq))
{
$qwerty=$rows['qtyleft'];
}
if ($qwerty !=0){
echo '<tr>';
//echo '<td>'.$row3['product_size_name'].'</td>';
echo '<td>'.$row3['price'].'</td>';
echo '<td>'.$row3['description'].'</td>';
echo '<td>'.'<input name="but" type="image" value="'.$row3['id'].'" src="images/button.png" onclick="return myFunction()" />'.'</td>';



echo '</tr>';
}
else
{
echo '"This Item is not Available"';
//echo '<td>'.'<h1>'.'"not available"'.'</h1>'.'</td>';
}

}

}
?>


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

最佳答案

您的 OR 应该是 AND:

if(a!=null && a!= "")

由于 a 不等于 null,因此条件为 true

关于javascript - 表单中的警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20462410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com