Dynamic ASP form - prevent user choosing default

Discussion in 'ASP General' started by iam247@gmail.com, Aug 7, 2005.

  1. Guest

    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>
     
    , Aug 7, 2005
    #1
    1. Advertising

  2. Curt_C [MVP] Guest

    wrote:
    > 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.

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 8, 2005
    #2
    1. Advertising

  3. Bullschmidt Guest

    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...


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Bullschmidt, Aug 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ford Desperado

    Choosing a default button

    Ford Desperado, Sep 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    509
    Steve C. Orr [MVP, MCSD]
    Sep 27, 2004
  2. Fredrik Lundh

    Re: choosing random dynamic port number

    Fredrik Lundh, Jan 3, 2008, in forum: Python
    Replies:
    2
    Views:
    1,157
    Grant Edwards
    Jan 4, 2008
  3. Replies:
    0
    Views:
    96
  4. nybble
    Replies:
    1
    Views:
    115
    Randy Webb
    Oct 2, 2005
  5. Stanimir Stamenkov

    Prevent form submission only from default action

    Stanimir Stamenkov, Mar 19, 2008, in forum: Javascript
    Replies:
    13
    Views:
    229
    Thomas 'PointedEars' Lahn
    Mar 20, 2008
Loading...

Share This Page