Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create A Pop-up Form to Confirm Input from User

Status
Not open for further replies.

mmignot

Programmer
Jul 16, 2001
44
US
Hello,

We have a form which the user can respond to 35 questions using radio buttons. These questions are optional, so when the user submits the form he/she may not have responded to some of the questions.

I would like to be able to have a form "pop-up" asking the users if they meant to skip questions, and if not go back and respond to the unanswered question(s). Can someone please help me understand how to do this?

Many thanks,
Mark M.
 
Thanks Lyndon,

I'm new to Coldfusion and Javascriopt,so I'm not sure how to find my answer -- All I would like to do is; if the user has skiiped some questions, after the "submit" button is hit, I'd like to dislay a pop-up window or message box that lets the user know that some questions were not answered, and if they meant to answer them they need to go back to the form. If you or anyone else can provide help or direct me to specific examples of this I'd really appreciate it!!!

Many thanks!!
 
What you want to do is set the onSubmit argument of your form to a javascript function. That function will check the values of the forms elements and, if needed, launch a comfirm or alert box. If that function returns true then the client focus will be changes to your action document, if it returns false focus will return to the form.

Try searching these ideas on the javascript forum. This is a very commom requirement there. Good luck.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
I saw on the JS board they had a lot of advice that you will need to consider like what to do if the client does not have javascript enabled and inerating through the forms elements looking for the elements that need a warning.

But here is an example of what I think your looking for. This is very basic so you can see the guts of an obsubmit js routine. Then you can move on to considering the more complex implementation you will need.

Code:
<script language="JavaScript" type="text/javascript">
	function noResponseWarning(){
		var returnValue=true;
		var messageString='Do you want to leave the following questions balnk?';
		if (document.getElementById('questionOne').value==''){
			messageString+='\n '+document.getElementById('questionOne').warn;
			returnValue=false;
		}
		if (document.getElementById('questionTwo').value==''){
			messageString+='\n '+document.getElementById('questionTwo').warn;
			returnValue=false;
		}
		if (document.getElementById('questionThree').value==''){
			messageString+='\n '+document.getElementById('questionThree').warn;
			returnValue=false;
		}
		if (!returnValue){
			alert(messageString);
		}
		return returnValue;
	}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
Survey
<cfform action="actionPage.cfm"  id="surveyForm" name="surveyForm" method="POST" onsubmit="return noResponseWarning()">
	What do you want? 
	<cfinput type="Text" 
			name="questionOne" 
			id="questionOne" 
			required="No" 
			warn="Question One" 
			size="50" 
			maxlength="75" ><br>
	Where do you need it? 
	<cfinput type="Text" 
			name="questionTwo" 
			id="questionTwo" 
			required="No" 
			warn="Question Two" 
			size="50" 
			maxlength="75"><br>
	When do you need it? 
	<cfinput type="Text" 
			name="questionThree" 
			id="questionThree" 
			required="No" 
			warn="Question Three" 
			size="50" 
			maxlength="75"><br>
	<input type="Submit" value="Done" >
</cfform>
</body>
</html>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Many thanks for the tip Lyndon!! Does it matter where the JS function is coded, or can I code it anywhere in the .cfm file??

Thanks again for your help, it is very much appreciated!!

M :)
 
It does not matter on this small example but you will probably want to keep it in a seperate .js file if you're going to do a lot of coding. The script tag has a "source" argument so you can include your scripts in any document.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
M
I just realized I didn't address the "confirm" box from your original request. Here is the modification.
Code:
<script language="JavaScript" type="text/javascript">
	function noResponseWarning(){
		var returnValue=true;
		var messageString='Do you want to leave the following questions balnk?';
		if (document.getElementById('questionOne').value==''){
			messageString+='\n '+document.getElementById('questionOne').warn;
			document.getElementById('questionOne').focus();
			returnValue=false;
		}
		if (document.getElementById('questionTwo').value==''){
			messageString+='\n '+document.getElementById('questionTwo').warn;
			if (returnValue){
				document.getElementById('questionTwo').focus();
			}
			returnValue=false;
		}
		if (document.getElementById('questionThree').value==''){
			messageString+='\n '+document.getElementById('questionThree').warn;
			if (returnValue){
				document.getElementById('questionThree').focus();
			}
			returnValue=false;
		}
		
		if (!returnValue){
			messageString+='\n Cancel to return to the form or OK to leave questions unanswered'
			return confirm(messageString);
			
		}
			else {
				return true;
			}
	}
</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top