showing alert box in php
NickName:kalvin Ask DateTime:2011-09-16T18:42:05

showing alert box in php

in the below code , the alert box is appearing in another window when values are not entered in the fields. but i want the alert box to appear in the same window of html page( detail.htm).how can i do this?

detail.htm:

<body>    
    <h1> Product: </h1>
    <form  action="product.php"  method="post"  >
        <input type="text" name= "product_id" size="15" />
        <input type="text" name= "price" size="10"/>
        <input type = "submit"  value = "enter" /> 
    </form>        
</body>

product.php:

if (empty($_POST["product_id"]) || empty($_POST["price"])) {
    echo "<script>alert('You must enter both values.')</script>";
} else {
    include 'product.htm';
}

Copyright Notice:Content Author:「kalvin」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7443492/showing-alert-box-in-php

Answers
Rijk 2011-09-16T10:44:29

You'll have to implement a client-side check in Javascript for that to happen.",


swdeveloper 2011-09-16T10:51:32

I think you should use client side validation:\n\n<script language=\"javascript\">\n function validate() {\n if (document.forms[0].product_id.value == \"\") {\n window.alert(\"You must enter both values\");\n return false;\n }\n if (document.forms[0].price.value == \"\") {\n window.alert(\"You must enter both values\");\n return false;\n }\n }\n</script>\n\n\nAnd then call the validate() function on onsubmit event of FORM like\n\n<form action=\"product.php\" method=\"post\" onsubmit=\"return validate();\">\n",


More about “showing alert box in php” related questions

javascript alert box not showing on php after header redirect

I am trying to display an alert box before redirecting to another page, here is my code, when I remove the header function it works properly but when it is here it will just redirect to the page wi...

Show Detail

showing alert box in php

in the below code , the alert box is appearing in another window when values are not entered in the fields. but i want the alert box to appear in the same window of html page( detail.htm).how can i...

Show Detail

How to display an alert box in php?

I want to display an alert box showing a message with PHP. If I not use alert box I get the right answer such "update subject set semester=2 where id=171 ". But after I change into alert box the an...

Show Detail

Alert box not working with php

&lt;?php if ($data == "") { ?&gt; &lt;script type="text/javascript"&gt; alert("review your answer1"); window.location.href = "index1.php"; &lt;/script&

Show Detail

Ajax alert box is showing HTML code

I am using jQuery AJAX to call a parameterised function on dynamic button click. Script and function is working fine. only problem is, it is showing all the HTML code into alert box. right from . I...

Show Detail

Alert box not showing when action from php js php

I have a problem in showing the alert box. This code for the rating star. rating.js $(document).ready(function(){ $('.post li').mouseout(function(){ $(this).siblings().andSelf().

Show Detail

Alert box in PHP - Making me crazy

I know this question is very common, I have search alot, and after alot of hard work, I am asking here. I simply want to show an alert box and redirect it to a page. The code below is redirectin...

Show Detail

How to alert box from ajax php function

I have function frm_trigger_entry_update this is the php function which is run in background i mean this is ajax php function. In this function i have write some jquery or javascript function whic...

Show Detail

Alert box not showing

I have my .js file in a seperate folder to the index.html Here is the contents of buildit.js //On change event for the textbox plate text function setValue(target){ var platetext = ...

Show Detail

Alert box is not showing in codeigniter models

in the model alert is not working. if condition is working,the only problem with the alert box, its not showing the dialog box.Please help.. public function setJumlahPenumpang ($idJadwal,$idPemesa...

Show Detail