Administration

Browse by Category
Personal Dashboard
Website Administration
Content Editor
Calendars
FusionPages
Classrooms
FusionTools
RSS
Data
Student Parent Connection
Other


Home > Content Editor

Search Knowledgebase
 

Jump to Category
 

FAQ(s) found under  Content Editor Showing 1 Of 4 Next

How do I make fields within a Form required?

It is possible to make fields required, but it will require knowledge of html, the use of the Advanced FCK Editor and the Source Button.

 

In the example below, the First Name field is a text box that is also marked as “required”. 

 

Please copy and paste the following information in the source code of the blank page that is to be used for a form that has required fields:

<html>
<head>
</head>
<body>
</body>
<script type="text/javascript">
function validate(form){
  var flag=0;
  for(i=0;i<form.length;i++){
      element=form.elements[i];
      //This is the bit that need to be duplicated for each required field.
      //just change the line below---the bit in the quotes needs to match the input name
      if(element.name=="first name"){
          if(element.value==""){
              alert("The field " +element.name+ " is a required field.");
              flag=1;
          }
      }
      //end of piece that needs duplicated.
      //This is the bit that needs to be duplicated for each required field.
      //just change the line below---the bit in the quotes needs to match the input name
      if(element.name=="first name"){
          if(element.value==""){
              alert("The field " +element.name+ " is a required field.");
              flag=1;
          }
      }
      //end of piece that needs duplicated.
      //This is the bit that needs to be duplicated for each required field.
      //just change the line below---the bit in the quotes needs to match the input name
      if(element.name=="city"){
          if(element.value==""){
              alert("The field " +element.name+ " is a required field.");
              flag=1;
          }
      }
      //end of piece that needs duplicated.
  }
  if(flag==1){
      return false;
  }else{
      return true;
  }
}

</script>

<form name="test" onsubmit="javascript: return validate(this);">
First Name:<input type="text" name="first name"><br />
Last Name:<input type="text" name="last name"><br />
City:<input type="text" name="city"><br />
<input type="submit" name="submit" value="test it">
</form>
</html>

In between the <form> and </form> tag, add additional fields. If you want them to be required, make sure to copy the “required” javascript and update the element name.

 

Please note: The element name must be the exact name used in the field.

 





Your Rating : Rating : Not rated


Powered by Comdev FAQ Support