Validate data using alert()

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

User avatar
popeye
New php-forum User
New php-forum User
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Validate data using alert()

Postby popeye » Sat Sep 15, 2007 1:26 pm

I am trying to validate the user's input. See codes below:

Code: Select all

<?php
$i_name='Your Name';
$i_s="
<!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>Untitled Document</title>
</head>
<body>
<script type='text/javascript'>
function checkForm(frm){
msg = '';
   if(!frm.Name.value){
      msg +=' - Name is a required field\n';
   }
   if(!frm.Email.value){
      msg +=' - Email is a required field\n';
   }
   if(!frm.Comments.value){
      msg += ' - Comments is a required field\n';
   }
   
   if(msg){
      alert('There was an error with your form:\n' + msg);
      return false;
    }
   
    document.form1.action='GoDoIt.php'; document.form1.submit();
}
</script>
<form id='form1' name='form1' method='post' action='' onsubmit='return checkForm(this)'>
    Name:<input name='Name' type='text' id='Name'  value='".$i_name."'>
    Email:<input name='Email' type='text' id='Email'>
    Comments:<textarea name='Comments' id='Comments'></textarea>
    Submit:<input type='submit' name='Submit' value='Submit'>
</form>
</body>
</html>";
echo $i_s;
?>



But when the submit is clicked, I do not get the Alerts and/or GoDoIt.php is never called because of "error on page". Any ideas? Thanks.

User avatar
popeye
New php-forum User
New php-forum User
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Postby popeye » Tue Sep 18, 2007 5:55 am

There must be something wrong with all you guys. I have not received any reply to my last posts. AT least let me know if there is anything wrong with my post or something else that I do not know :?

User avatar
popeye
New php-forum User
New php-forum User
Posts: 120
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Postby popeye » Thu Sep 20, 2007 12:32 pm

:)

Thanks a lot. I see my mistake. I appreciate your respond.

:D


Return to “HTML Basics”

Who is online

Users browsing this forum: No registered users and 0 guests

cron