html - postback to server executing different queries -
i have few <div>
inside forms, each thing inside div
contains specific form. when user presses submit button, want execute different action based on
<form method="get" action="addprogramtodb.jsp"> <select name="cid" style="display: none;"> <option>1</option> <option>2</option> </select> <div id="1"> </div> <div id="2"> </div> <div id="3"> </div> <input type="submit"/> </form>
when user presses submit button want program execute different queries based on div in.... based on div id, or somehow..
give submit button name , value usual way.
<input type="submit" name="action" value="action1"> ... <input type="submit" name="action" value="action2"> ... <input type="submit" name="action" value="action3">
the pressed button namely available request parameter well.
string action = request.getparameter("action"); if ("action1".equals(action)) { // action1 button pressed. } else ("action2".equals(action)) { // action2 button pressed. } else ("action3".equals(action)) { // action3 button pressed. }
you can if necessary give them different name instead , nullcheck each request parameter.
<input type="submit" name="action1" value="this more i18n friendly"> ... <input type="submit" name="action2" value="blah"> ... <input type="submit" name="action3" value="more blah">
with
if (request.getparameter("action1") != null) { // action1 button pressed. } else (request.getparameter("action2") != null) { // action2 button pressed. } else (request.getparameter("action3") != null) { // action3 button pressed. }
or, if in their own <form>
, can pass hidden input along.
<form> <input type="hidden" name="action" value="action1"> ... </form> <form> <input type="hidden" name="action" value="action2"> ... </form> <form> <input type="hidden" name="action" value="action3"> ... </form>
with same server-side handling in 1st example.
Comments
Post a Comment