Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to prevent the submit to take place if nothing has been selected?

Replies are listed 'Best First'.
Re: empty submit
by dreadpiratepeter (Priest) on Mar 22, 2004 at 14:14 UTC
    If I am interpreting what you want to do properly, this is a JavaScript question, not a Perl question.
    Stopping the browser from submitting has to be done from the JS.
    You would need to write an onSubmit handler that checks all your fields for values and returns false if they are all empty.


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
      Does it have to be Javascript?

      Can't it be done with other scripting languages (such as VBScript or PerlScript -- hey , that's an idea!)?

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Yes it could, but since the lion's share of client side scripting is done in JS, I thought it the appropriate answer. (Particularly when Perl is the server-side language. I would think that most people using VBScript would also be using ASP).

        I've been doing web work since the web began and I have never once been involved in or even heard of the project that uses PerlScript for the client side.


        -pete
        "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
Re: empty submit
by liz (Monsignor) on Mar 22, 2004 at 23:10 UTC
    If you want to do this from the server, you might want to return status code 204 without any body. From RFC 2616:
    204 No Content
    The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

    If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

    The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

    Liz