[Javascript] Can this be done?

David Lovering dlovering at gazos.com
Thu Oct 30 09:56:43 CST 2003


This all gets back to the deficiencies of CGI/BIN-esque coding practices.
The way I'd handle it is to use a 'Null-form', wherein the action is
nuked --

  <FORM name='myform' id='myform' method='post'
action='javascript:void(null)'  enctype='multipart/form-data'>

  all your data fields go here

    <input name='A_button' onClick='doProcedureA(this)' value='Procedure A'
type='button'>
    <input name='B_button' onClick='doProcedureB(this)' value='Procedure B'
type='button'>

  </FORM>

Then, in the javascript preamble I'd define the two procedures (doProcedureA
and doProcedureB) to submit ONLY the fields you want, and invoke ONLY the
actions you need.  In this way you can make one form serve a multitude of
purposes without having to build a huge-ass CGI/BIN handler to filter each
one.  This is also useful if you want to send the 'form' data to different
machines or
handler directories based upon which pseudo-submit button the user clicks.

There are admittedly some oddities in the way Micro$oft handles forms within
the JSP realm, but as no one with any discernment
actually uses Micro$oft's JSP tool library, this is generally OK.

In short, I NEVER use the generic CGI/BIN handler architecture in its most
basic form.  It is too clumsy, and doesn't give enough
bang for the buck.

-- Dave Lovering

----- Original Message ----- 
From: "Roland Dong" <rdong at cait.org>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, October 30, 2003 8:27 AM
Subject: [Javascript] Can this be done?


> I have a form which collects student data and submit them to a jsp program
> which then update the database.  I want to have two buttons,  A and B.
> Clicking on button A should update the database and show the updated
> result(action A).  Clicking on button B  should also update the database
but
> then redirect to a different page(action B).
>
> I know you could use two separate forms to do that. However you would need
> to manage to pass all the values again from action A.
>
>
> Is it possible to use one form and one action but send a flag to indicate
if
> it should action A or action B?  So I want clicking on button A to pass
flag
> value "0" to update.jsp and clicking on button B to pass flag value "1" to
> update.jsp, so that update.jsp will know what action to take.
>
>
> I tried something like this but it is not working.
>
> javascript:
> =============================================
> function A() {
>
>         if(document.reqForm.flag.value == "")
>         { document.reqForm.flag.value = "0";
>         }
>          document.reqForm.submit();
> }
>
>
> function B() {
>
>         if(document.reqForm.flag.value == "")
>         { document.reqForm.flag.value = "1";
>         }
>          document.reqForm.submit();
> }
>
> ============================================
>
> form:
> =============
> <form name="reqForm" method="post" action="update.jsp">
> Name    <input type="text" name="name" value="">
> ClassID  <input type="text" name="classId" value="">
> Grade     <input type="text" name="grade" value="">
>
> ......
> .......
> .......
>
> <input type="hidden" name="flag" value="">
> <input type="button" value="A" onClick="return A()">
> <input type="button" value="B" onClick="return B()">
>
> </form>
>
> Can this be done? Please throw some light on this.
>
> Thanks,
>
> RD
>
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>





More information about the Javascript mailing list