0

Hi guys, I have a php page and the alert i write in JavaScript. When the users fill up the form and click on submit button on next page it will out the alert if do not fill up the name. So the question how can make it display on the same page when user didnt fill up complete of the form

Here the code:

if($from == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent, You have not entered a Name, please go back fill up and try again!!')</script>";}

else {

if($phone == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Phone Ext, please go back fill up and try again!!')</script>";}

else {

if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";}

else

{

$ok = @mail($to, $subject, $message, $headers)
2
Contributors
1
Reply
4
Views
8 Years
Discussion Span
Last Post by sysel
0

Add onSubmit event, and write a JavaScript function to evaluate the submitted form before sending.

Or use

<input type="button" value="Send!" onClick="evaluate(this)">

instead the submit button and the necessary JavaScript

<script>
function evaluate(oMyForm)
{ ... 
  if(oMyForm.inputName.value==''){alert('e-mail cannot be sent ...')}
  else {oMyForm.submit()} .....
}
</script>

something like this. I suppose the goal is to do validation and alert before the form data is send to the server - hence it has to be don on client side.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.