Solved

validation checking on text boxes

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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 …

734 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