Dynamic ASP form - prevent user choosing default

I

iam247

Hi

I have an ASP form which only includes an option list. The list is
dynamically created but includes a default value, which is an
instruction "Select a group".

The code is shown at bottom.

I want to ensure the user does not submit the form with the default
value selected.

I think something like the javscript handler available at:
http://www.devx.com/tips/Tip/13767 might be what I need.

(script extract)

<SCRIPT>
function checkvalue() {
if (triviaform.TriviaAnswer.optio­ns[0].selected) {
alert('You must enter your response.');
event.returnValue=false;
}
}
</SCRIPT>

However this script works for a static form with pre numbered options
ie option 0 is the default option.

How do I modify this script (or get another one) which will prevent my
default value being selected?

Thanks ColinK

MY FORM

<form action="LeaderSelect2.asp" method="get">
<select name="GroupName">
<option>Select a Group</option>
<%
' Continue until we get to the end of the recordset.
Do While Not rsGroupP.EOF
' For each record we create a option tag and set it's value to
the GroupID
%>
<option value="<%= rsGroupP.Fields("GroupName") %>"><%=

rsGroupP.Fields("GroupName") %></option>
<%
' Get next record
rsGroupP.MoveNext
Loop

End If
%>
<input type="submit" name="Submit" value="Add a Leader to this
Group">
</form>
 
C

Curt_C [MVP]

Hi

I have an ASP form which only includes an option list. The list is
dynamically created but includes a default value, which is an
instruction "Select a group".

Give the "select a group" item a specific value (or no value) and check
for that when they click the button.
 
B

Bullschmidt

And validation can be done clientside with JavaScript:

Javascript Field Validations -- Client Side Scripting by Nannette
Thacker - 8/19/1999
http://www.shiningstar.net/articles/articles/javascript/javascriptvalida
tions.asp?ID=AW

Form Validation Using Javascript - 9/19/1998
http://www.4guysfromrolla.com/webtech/091998-1.shtml
Good tips such as saving JavaScript functions in a file called
DataValidation.js and including this in pages that need this.
JavaScript functions.

WebDaily: Your daily source for Web Technology Tips and Tricks! -
10/27/1998
http://www.4guysfromrolla.com/webtech/102798-1.shtml
Just checks if fields filled in.

Or server-side with ASP (my favorite):

Server-Side Form Validation by Dianna Leech - 12/1/1999
http://www.4guysfromrolla.com/webtech/120199-1.shtml

An Email Validation Routine by João Vieira - 4/11/1999
http://www.4guysfromrolla.com/webtech/041199-1.shtml
Somewhat shorter.

An Email Validation Script by Ben Durbin - 5/19/1999
http://www.4guysfromrolla.com/webtech/051999-1.shtml
Longer.

Form Handler: Some light form validation and error notification.
http://www.asp101.com/samples/form_handler.asp
Uses function to loop thru all fields in a form.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top