[thelist] Brain fart html w/asp (revisited)

Andrew Clover and at doxdesk.com
Fri Apr 26 15:54:00 CDT 2002


Chris W. Parker <cparker at swatgear.com> wrote:

> what you can do instead of have two forms, or a nested form
> (which i don't think works?)

(no, it doesn't.)

> for example you will have one form but allow the user to either
> "save Article" or "Submit for Review" their article.

You can't have a form with two different destinations. There's
two approaches to this, the client-side way and the server-side
way.

The client-side way consists of using JavaScript to change the
destination of the form before it is submitted:

  <form method="post" action="submit.asp"><div>
    <input type="radio" name="action" value="save"
     onclick="this.form.action= 'save.asp';" /> Save
    <input type="radio" name="action" value="submit" checked
     onclick="this.form.action= 'submit.asp';" /> Submit
  </div></form>

The obvious drawback of this technique is that it won't work if
client-side-scripting is unsupported or disabled.

The server-side way is generally better:

  <form method="post" action="submitorsave.asp"><div>
    <input type="radio" name="action" value="save" /> Save
    <input type="radio" name="action" value="submit" checked /> Submit
  </div></form>

(or, probably better to use two buttons:)

  <form method="post" action="submitorsave.asp"><div>
    <input type="submit" name="action" value="Save" />
    <input type="submit" name="action" value="Submit" />
  </div></form>

Then the submitorsave.asp script has to look at the submitted
'action' value to see what exactly to do.

This may be quite tricky if the actions for different buttons on
the form have to do very different things. In this case it is
better to use shared functions, so the script just calls whichever
one is necessary for the action. Exactly how you declare a function
to be shared across scripts depends on what language and framework
you are using. I believe the idiom for ASP+VBScript is to use
includes. This is awful but then so is most of the rest of VBScript
so at least it's a good fit. ;-)

But I would imagine the 'save' and 'submit' actions would be similar
enough that it would make sense to put them in the same script
anyway.

--
Andrew Clover
mailto:and at doxdesk.com
http://and.doxdesk.com/



More information about the thelist mailing list