Solved

validation checking on text boxes

Posted on 2003-11-03
5
194 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now