RE: Javascript Form Problem

by "Charlton, Mark" <Mark.Charlton(at)saint-gobain.com>

 Date:  Fri, 23 Mar 2001 11:30:31 -0500
 To:  =?iso-8859-1?Q?=27Mikael_Bystr=F6m=27?= <sunergy(at)mac.com>,
HWG Languages <hwg-languages(at)hwg.org>,
sandy(at)sannicron.com
  todo: View Thread, Original
The reason I didn't go into it was I wasn't sure if it answered the
question, but since it may.

If you create some radio buttons on a form in a file called say quest.asp
Then add some script to the header as shown below.

That will go through and test all radio groups called R1 through R2 and all
test cells called T1 throught T1.  You can put multiple individual tests in
if your naming isn't that simple.  The code in the body is to flag up any
skipped questions where no value was submitted, but the submit button was
pressed, ensuring that the messages don't show when the form first loads.

In the header you can do things like write javascript code to call alerts
and other routines which get called from the fail check routine.  This has
been tested briefly and it should work.  Unfortunately I don't have a public
server I can host this on so you can see, but if anyone has an ASP server
and you copy this page, remove the dots and call it QUEST.ASP you should see
how it works.

This isn't the slickest code ever, but it should illustrate the point and
show how you can do validation.

<.%@ Language=VBScript %>

<.% 

dim i
dim fComplete

fComplete = true
'
'	Check if form has been submitted
'	If the count is > 0 then it means that field is in the forms
collection that was submitted
'
if Request.Form("Submit").Count > 0 then   
	'
	'Go through all question groups
	'
	for i = 1 to 2
		if Request.form("R" & i).count = 0 then
			'	
			'	No option selected in Ri
			'
			fComplete = false
		end if
	next
	for i = 1 to 1 
		if Request.form("T" & i).count = 0 or request.form("T" & i)
= "" or isnull(request.form("T" & i))  then
			'	
			'	No option selected in Ti
			'
			fComplete = false
		end if	
	next
	if fComplete = true then
		'
		'	Either pass on for to another page, or do some kind
of processings
		'	Store records in a DB etc
		'
		Response.write "<.script language='javascript'> " & vbcrlf
		Response.write "alert('All Complete, THANK YOU');" & vbcrlf
		Response.write "<./script > " & vbcrlf	
	else
		'
		'	Depending on how you wish to go about it you can
either flag up 	
		'	Skipped questions by setting other flags tested at
form write level
		'	Or any other action required
		'
		Response.write "<.script language='javascript'> " & vbcrlf
		Response.write "alert('Please make sure you complete all
questions before submitting');" & vbcrlf
		Response.write "<./script > " & vbcrlf		
	end if
end if

%>
<.HTML>
<.HEAD>
<./HEAD>
<.BODY>
<.form action="quest.asp" method=post name=questions>

<.% if request.form("R1").count = 0 and request.form("submit").count >0
then
	response.write "<.H2>Please complete this question<./h2>"
    end if %>	
<.input type=radio name=R1 value=bob <.% if request.form("R1") = "BOB" then
%> CHECKED <.% end if %> >BOB<.br>
<.input type=radio name=R1 value=FRED <.% if request.form("R1") = "BOB" then
%> CHECKED <.% end if %>>FRED<.br>
<.input type=radio name=R1 value=STEVE <.% if request.form("R1") = "STEVE"
then %> CHECKED <.% end if %>>STEVE<.br>
<.input type=radio name=R1 value=JAMES <.% if request.form("R1") = "JAMES"
then %> CHECKED <.% end if %>>JAMES<.br>
<.input type=radio name=R1 value=JOHN <.% if request.form("R1") = "JOHN"
then %> CHECKED <.% end if %>>JOHN<.br>
<.hr>
<.% if request.form("R2").count = 0 and request.form("submit").count >0
then
	response.write "<.H2>Please complete this question<./h2>"
    end if %>
<.input type=radio name=R2 value=red <% if request.form("R2") = "red" then
%> CHECKED <.% end if %> >red<.br>
<.input type=radio name=R2 value=green <% if request.form("R2") = "green"
then %> CHECKED <.% end if %> >green<.br>
<.input type=radio name=R2 value=blue <% if request.form("R2") = "blue" then
%> CHECKED <.% end if %> >blue<.br>
<.hr>
<.% if request.form("T1").count = 0 and request.form("submit").count >0
then
	response.write "<.H2>Please complete this question<./h2>"
    end if %>
<.input type=text name=T1 value="<.%=request.form("T1")%>">
<hr>
<.input type=submit name=submit >

<./form>

<./BODY>
<./HTML>

-----Original Message-----
From: Mikael Byström [mailto:sunergy(at)mac.com]
Sent: Thursday, March 22, 2001 7:55 PM
To: Charlton, Mark; HWG Languages; sandy(at)sannicron.com
Subject: RE: Javascript Form Problem


Charlton, Mark Mark.Charlton(at)saint-gobain.com did solemnly swear 3/23/01 
00.34 that

>If you have microsoft IIS and want any help on an ASP validation
>routine feel free to drop me a line.
 Why not discuss it here at HWG Languages? 

Best ((Vibes))


Mikke Bystrom
Applied Design Intelligence
CHVCK Talent Pool
sunergy(at)mac.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.