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)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.