Link to home
Start Free TrialLog in
Avatar of royalcyber
royalcyber

asked on

How can I change the value of a hidden variable if the user clicks on a specific button

Following is the code of my form and buttons. Based on the update variable I show differnt buttons

Now the problem is that if the update value = -1, the JSP shows 2 buttons SAVE and SAVE AS NEW.
When user clicks on SAVE it update the record based on the hidden id "ueid"
Now what I need is that when the user clicks on SAVE AS NEW it should change the ueid to "". If I can do that I can reuse the entire code

Any help will be greatly appreciated

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<form  name="myform" enctype="multipart/form-data" action="chapter_admin?action=add_documents" method="post" onSubmit="return verify();">
<% String document_id = null;
 
   document_id =  new Integer(selected_document.getDocument_ID()).toString();
   %>
<input type="hidden" name="ueid" value="<%= document_id %>">
.
.
.

<% if(update == "-1"){  %>
<td><input type="submit"  class="button"  value="Save" onClick="parent.location='chapter_admin?action=update_documents&eid=<%= selected_document.getDocument_ID() %>'"></td>
<td><input type="button"  class="button" value="New" onClick="parent.location='chapter_admin?action=show_documents'"></td>
<% } else { %>
<td><input type="submit" class="button" value="Add Document"></td>
<% } %></tr>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of royalcyber
royalcyber

ASKER

Actually this is the code which I am looking for

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<tr>
<% if(update == "-1"){  %>
<td><input type="submit"  class="button"  value="Save Event" onClick="parent.location='chapter_admin?action=update_events&eid=<%= selected_event.getEvents_ID() %>'"></td>
<td><input type="submit"  class="button" value="Save As New" onClick="parent.location=action='chapter_admin?action=add_events&value=addnew'"></td>
<% } else { %>
<td><input type="submit" class="button" value="Add Event"></td>
<% } %></tr>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now if I use two buttons with type="submit" it gives me wierd results such that when i try to add an event it adds two events instead of one

Also if I try to use type="button" it doesn't submit all the values of the form to the servlet

Now what I need is that if there is a way I can submit all the form to the request parameter, so that I can retreive it in the servlet and also get the value parameter of the buton clicked

Thanks

"wierd results"

what this mean?
By "wierd result" I meant that when I run the application and click on the button to add the data to the database. It adds the data twice in the database, which I guess is beacuase of two submit buttons.