Important alert: (current site time 7/15/2013 12:53:59 PM EDT)
 

VB icon

Advanced Form Filter - Survey Voting Rating System Snippet

Email
Submitted on: 5/2/2002 9:10:36 AM
By: Kevin O'Neill  
Level: Intermediate
User Rating: By 2 Users
Compatibility: JavaScript
Views: 14222
(About the author)
 
     //The following is a code snippet of a survey //I created for a voting rating system. The javascript function which follows //checks to make sure an employee field is selected, the points box is an actual //number, a whole number and not negative. Other features of the function include: //Checks that if the points field is filled in but the firm is not - then the user is alerted. //Checks that if the firm is filled in but the points are not - then the user is alerted. //Checks that if you fill in data for a other name then move to the dropdown and make a //selection your entry in the text field is blanked out, the firm and coverage fields //work the same way //Finally, the user is limited to 100 chars for the comment box and for convenience sake, the user gets //displayed a running total of their points when they submit the form. //Add cards by copying and pasting from to and then revamp all //the javascript to add more then one card (my survey had 25 cards)

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Advanced Form Filter - Survey Voting Rating System Snippet
' Description://The following is a code snippet of a survey
//I created for a voting rating system. The javascript function which follows 
//checks to make sure an employee field is selected, the points box is an actual 
//number, a whole number and not negative. Other features of the function include: 
//Checks that if the points field is filled in but the firm is not - then the user is alerted.
//Checks that if the firm is filled in but the points are not - then the user is alerted.
//Checks that if you fill in data for a other name then move to the dropdown and make a 
//selection your entry in the text field is blanked out, the firm and coverage fields 
//work the same way
//Finally, the user is limited to 100 chars for the comment box and for convenience sake, the user gets 
//displayed a running total of their points when they submit the form.
//Add cards by copying and pasting from <!--card 1--> to <!--end card 1--> and then revamp all 
//the javascript to add more then one card (my survey had 25 cards)
' By: Kevin O'Neill
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2852&lngWId=14'for details.'**************************************

<html>
<head>
<title>Advanced Form Filter - Survey Voting Rating System</title>
<script language="javascript">
//The following is a code snippet of a survey
//I created for a voting rating system. The javascript function which follows 
//checks to make sure an employee field is selected, the points box is an actual 
//number, a whole number and not negative. Other features of the function include: 
//Checks that if the points field is filled in but the firm is not - then the user is alerted.
//Checks that if the firm is filled in but the points are not - then the user is alerted.
//Checks that if you fill in data for a other name then move to the dropdown and make a 
//selection your entry in the text field is blanked out, the firm and coverage fields 
//work the same way
//Finally, the user is limited to 100 chars for the comment box and for convenience sake, the user gets 
//displayed a running total of their points when they submit the form.
//Add cards by copying and pasting from <!--card 1--> to <!--end card 1--> and then revamp all 
//the javascript to add more then one card (my survey had 25 cards)
			var fieldArray = new Array("r9");
			function checkData(formObj)
			{
			var runningTotal = 0;
			//point box checks
 
			if (form1.r9.value == "")
			{
			form1.r9.value = 0
			}
	
				
			for(var i = 0; i < fieldArray.length; i++)
			{
			var textObj = eval("formObj." + fieldArray[i]);
			if(isNaN(textObj.value))
			{
			alert("Numbers only please!");
			textObj.focus();
			textObj.select();
			return false;
			}
	
			else if(textObj.value.indexOf(".") != -1)
			{
			alert("Whole numbers only please!");
			textObj.focus();
			textObj.select();
			return false;
			}
			
				else if(textObj.value < 0)
					{
						alert("Positive numbers only please!");
						textObj.focus();
						textObj.select();
						return false;
					}
			if(textObj.value != "")
				{
		
					runningTotal += parseInt(textObj.value);
		
				}
			}
			if(runningTotal)
			
				{
					var surveyTotal = eval(form1.r9.value) // + next card you add
					var surmsg = confirm("Your current point total is " + surveyTotal + " is this OK");
				
					if(!surmsg)
				{ 
					return false;
			}
		}
		//employee & firm field checks
			if (form1.r1.value == "")
				{
					alert("Please enter a value for the employee name field.");
					form1.r1.focus();
	
					return false;
	
				} 
				if (form1.r9.value != 0 && (form1.r5.value == "" && form1.r6.value == ""))
			{
				alert("Please enter a value for the firm field.");
					form1.r5.focus();
	
					return false;
	
			} 
	
			
			//point checks
			if (form1.r9.value == 0 && (form1.r5.value != "" || form1.r6.value != ""))
				{
						alert("Please enter a value for the points field.");
						form1.r5.focus();
	
				return false;
	
				} 
	
			 	
			//comment boxes checks	
	
			var maxlength=100
				if (form1.r10.value.length>maxlength)
	
			{
				alert("Please restrain your input to less then 100 characters!")
					form1.r10.focus();
				return false;	
				}
			
					return true;
				}
					</script>
</head>
<body>
				
<form action="somepage.htm" method="POST" onSubmit="return checkData(this)" name="form1" id="form1">
<p align="center">
 <hr size="1" color="black">
 <table cellpadding="5" cellspacing="0" width="50%">
<tr>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Employee Name:</font>
</td>
<td valign="top" align="left" width="50%">
 <input type="hidden" name="scaleorder" value="standard">
 <select name="r1" size="1" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
			<option name="" value=""> </option>
<option name="2" value="1">Employee 1</option>
 <option name="3" value="2">Employee 2</option>
 </select>
 
</td>
</tr>
</table>
	<!--card 1-->
	<fieldset>
	<legend>Vote 1</legend>
	<table cellpadding="5" cellspacing="0" width="50%"> 
<tr>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Name:              </font>
</td>
<td valign="top" align="left" width="50%">
 
 <select name="r2" size="1" onClick="JavaScript:document.form1.r3.value=''" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
			<option name="" value=""> </option>
 <option name="1" value="1">Analyst 1</option>
 <option name="2" value="2">Analyst 2</option>
</select> 
 
</td>
 
 
 <td valign="middle" align="left" width="20%">
 <font face="Arial" size="2" color="red">   OR</font>
 </td>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">         Other<br>         Last:</font>
</td>
<td>
 
       <input type="text" maxlength="25" size="13" name="r3" onClick="JavaScript:document.form1.r2.selectedIndex=0" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
 
</td>
 
 
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Other First:</font>
</td>
<td>
 
 <input type="text" maxlength="25" size="10" name="r4" onClick="JavaScript:document.form1.r2.selectedIndex=0" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
 
</td>
</tr>
 </table>
 
 
 <table cellpadding="5" cellspacing="0" width="50%">
<tr>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">   Firm:              </font>
</td>
<td valign="top" align="left" width="50%">
 
 <select name="r5" size="1" onClick="JavaScript:document.form1.r6.value=''" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
			<option name="" value=""></option>
<option name="1" value="1">Firm 1</option>
 <option name="2" value="2">Firm 2</option>
 
 </select>
 
</td>
	<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Firm<br>Other:</font>
</td>
<td>
 
     <input type="text" maxlength="30" size="30" name="r6" onClick="JavaScript:document.form1.r5.selectedIndex=0" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
 
</td>
</tr>
 </table>
 
 <table cellpadding="5" cellspacing="0" width="50%">
<tr>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Coverage: </font>
</td>
<td valign="top" align="left" width="50%">
 
 <select name="r7" size="1" onClick="JavaScript:document.form1.r8.value=''" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
			<option name="" value=""> </option>
<option name="1" value="1">Coverage 1</option>
 <option name="2" value="2">Coverage 2</option>
 
 </select>
 
</td>
 
	 <td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Coverage<br>Other:</font>
</td> 
<td>
 <input type="text" maxlength="30" size="30" name="r8" onClick="JavaScript:document.form1.r7.selectedIndex=0" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
 
</td>
</tr>
 </table>
 <table cellpadding="5" cellspacing="0" width="63%">
<tr>
<td valign="middle" align="left" width="50%">
 <font face="Arial" size="2" color="#000000">Points:</font>
</td>
 
<td>
 
 <input type="text" maxlength="3" size="3" name="r9" style="BACKGROUND-COLOR: lightgoldenrodyellow;">
 
</td>
 
 
<td valign="middle" align="left" width="25%">
 <font face="Arial" size="2" color="#000000">Comments:</font>
</td>
<td>
 
 <textarea cols="25" rows="4" maxlength="100" name="r10" style="BACKGROUND-COLOR: lightgoldenrodyellow;">


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
3/9/2006 9:35:15 AMwasee

give this code in seprate zip folder


(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.