[Javascript] Can this be done?

Roland Dong rdong at cait.org
Thu Oct 30 09:27:41 CST 2003


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







More information about the Javascript mailing list