Note that there are some explanatory texts on larger screens.

plurals
  1. POAlert message in Forms
    primarykey
    data
    text
    <p>I still can't get the right flow for this. I know it's simple and i think that my code is right but still the alert message is showing when i hit the buy button even if the input box is null. What i wanted is that no alert message will show if the input box is null but if the input box is filled then that;s the only time where the alert message will show when button is clicked. Here is my code:</p> <pre><code> &lt;?php require_once('auth.php'); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;title&gt;Athan Motorcycle&lt;/title&gt; &lt;style type="text/css"&gt; &lt;!-- .style1 { color: #000000; font-weight: bold; font-size: 24px; } --&gt; &lt;/style&gt; &lt;!--&lt;script type="text/javascript"&gt; function validateForm() { var a=document.forms["abc"]["qty"].value; if ((a==null || a=="")) { alert("Please specify the quantity."); return false; } } &lt;/script&gt;--&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="saveorder.php" name="abc" method="post"&gt; &lt;input name="id" type="hidden" value="&lt;?php echo $_SESSION['SESS_MEMBER_ID']; ?&gt;" /&gt; &lt;input name="transcode" type="hidden" value="&lt;?php echo $_SESSION['SESS_FIRST_NAME']; ?&gt;" /&gt; &lt;table width="400" border="0" cellpadding="0" cellspacing="0"&gt; &lt;?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 '&lt;tr&gt;'; echo '&lt;td width="80"&gt;&lt;img alt="Motor" src="images/motor/'.$row3['product_photo'].'" /&gt;&lt;/td&gt;'; echo '&lt;td width="200"&gt;&lt;span class="style1"&gt;'.'&lt;/span&gt;&lt;/td&gt;'; echo '&lt;td width="120"&gt;&lt;/span&gt;&lt;/td&gt;'; echo '&lt;/tr&gt;'; echo '&lt;tr&gt;'; echo '&lt;td width="80"&gt;&lt;input name="name" type="text" value="'.$row3['partsname'].'" readonly/&gt;&lt;input name="ingre" type="hidden" value="'.$row3['product_ingredients'].'"/&gt; &lt;input name="ids" type="hidden" value="'.$row3['id'].'"/&gt;&lt;/td&gt;'; echo '&lt;td width="120"&gt;&lt;/span&gt;&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/table&gt; &lt;br /&gt; &lt;label style="color:#000000;"&gt;Qty: &lt;input type="number" min="1" id="qty" name="qty" required = "required" /&gt; &lt;/label&gt; &lt;br /&gt; &lt;table width="400" border="0" cellpadding="0" cellspacing="0" style="color:#000000;"&gt; &lt;tr&gt; &lt;!--&lt;td width="179"&gt;Size&lt;/td&gt;--&gt; &lt;td width="128"&gt;Price&lt;/td&gt; &lt;td width="179"&gt;Description&lt;/td&gt; &lt;td width="93"&gt;Selection&lt;/td&gt; &lt;/tr&gt; &lt;?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 '&lt;tr&gt;'; //echo '&lt;td&gt;'.$row3['product_size_name'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row3['price'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row3['description'].'&lt;/td&gt;'; echo '&lt;td&gt;'.'&lt;input name="but" type="image" value="'.$row3['id'].'" src="images/button.png" onclick="return myFunction()" /&gt;'.'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } else { echo '"This Item is not Available"'; //echo '&lt;td&gt;'.'&lt;h1&gt;'.'"not available"'.'&lt;/h1&gt;'.'&lt;/td&gt;'; } } } ?&gt; &lt;/table&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; function myFunction() { var a=document.forms["abc"]["qty"].value; if (a!=null || a!= ""){ alert("Item has been successfully added to your Cart"); } } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload