Solved

validation checking on text boxes

Posted on 2003-11-03
5
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

624 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