[Javascript] Can this be done?

Alan Easton alan.easton at unn.ac.uk
Thu Oct 30 09:41:14 CST 2003


Maybe try onclick events on each button. Then have 2 functions, each
function submits the form to the same page, but uses a select statement to
go to a particular part of the same form. Then you could have 1 select case
do one thing and the 2nd one do another.

onClick="onChange(this.form,'gotoA')"

onClick="onChange(this.form,'gotoB')"

Look at Javascript select cases, it should help.


-----Original Message-----
From: Roland Dong [mailto:rdong at cait.org]
Sent: 30 October 2003 15:28
To: [JavaScript List]
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