Solved

validation checking on text boxes

Posted on 2003-11-03
5
202 Views
Last Modified: 2010-04-09
I hv a simple feedback form page where i want to validate empty text boxes
for eg: email text box with comment area box
when user donot insert email information and comment it should provide alert mes like "Please insert ......."
then only submit form should proceed
please suggest me
Regards
0
Comment
Question by:happyprogramming
  • 3
5 Comments
 
LVL 5

Expert Comment

by:ho_alan
ID: 9676743
<form name=fm1 onsubmit="check()">
<input type=text name=email>
<input type=text name=comment>
</form>

<script>
function check()
{
     valid=true;
    fmSize=document.fm1.length;
    for i=0;i<fmSize;i++
       if(document.fm1.elements[i].value=""){
           alert("please insert : " +document.fm1.elements[i].name)
       valid=false;
      }
   return  valid;
}
</script>
0
 

Author Comment

by:happyprogramming
ID: 9676781
This is my form page where i want to make sure user has put the valuyes

<html>
    <head>
          <title>User Feedback-From</title>
    </head>

    <body bgcolor="white" text="black" background=" "><center><font face=Courier New>

    <div align="center"><img src="reallogo.bmp" align="center" alt="LOGO"></div>
    </br>
    <center><font face="Verdana"><h2>User Feedback-Comment Form</h2>
<div align="center">
     </br>

<form method=post action="processfeedback.php">
   Your name: <br />
     <input type=text name="name" size=40><br />
   Your email address <br />
     <input type=text name="email" size=40><br />
<font size='1' color='blue'>*Please provide correct e-mail id to get reply.</font></br></br>
   <b>Your feedback:<br />
     <textarea name="feedback" rows=10 cols=70>
     </textarea><br />
     <input type=submit value="Submit  ">
     <input type=reset value="Clear All">
</form>
     </body>
0
 
LVL 5

Expert Comment

by:ho_alan
ID: 9676798
this function is general checking function
it should work in your  case

<form method=post action="processfeedback.php" onsubmit="check();">

0
 
LVL 5

Expert Comment

by:ho_alan
ID: 9676967
<form name=fm1 method=post action="processfeedback.php" onsubmit="check();">
0
 
LVL 2

Accepted Solution

by:
Netwing earned 40 total points
ID: 9677029
this should work:


<html>
    <head>
          <title>User Feedback-From</title>
             
              <script type="text/javascript">
<!--
function validateForm(objForm){
     var bValid=true;
     for (var i=0; i< objForm.elements.length && bValid;i++){
          if(objForm.elements[i].type.indexOf('select')!=-1){
                if(!(objForm.elements[i].value)){
                   bValid=false;
                    alert("Please insert ......");
                }
           }else{
               if(!objForm.elements[i].value){
                  bValid=false;
                  alert("Please insert ......");
               }
           }
   }
return bValid;
}

-->
</script>
             
             
    </head>

    <body bgcolor="white" text="black" background=" "><center><font face=Courier New>
<form method=post action="#" onSubmit="return validateForm(this)">
  <p>Your name:
    <input type=text name="name" size=40>
    <br>
    Your email address
    <input type=text name="email" size=40>
  </p>
  <p><font size='1' color='blue'>*Please provide correct e-mail id to get reply.</font>
    <br>
    Your feedback: <br>
    <textarea name="feedback" cols="50" rows="5"></textarea>
    <br>
    <input type=submit value="Submit  ">
    <input type=reset value="Clear All">
  </p>
</form>
</body>
</html>
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Put shading on half of picture 8 43
How to make a moving character 3 58
Html5 string 3 23
Create CSS Animation for Page Transitions 4 26
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question