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>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
royalcyberAsked:
Who is Participating?
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
pass the value as a parameter to a function in the onClick of that button and then assign the vaue to the hidden variablr inside that function.

onClick="parent.location='chapter_admin?action=show_documents, setValue('hello')"

and now you can set this value of hello hello to your variable in that function.

Thank You.
0
 
smaccariCommented:
Is that what you need?

<% String document_id = "";
  if ((request.getParameter("action"))&&(request.getParameter("action").equals("update_documents")))
   document_id =  new Integer(selected_document.getDocument_ID()).toString();
   %>
0
 
royalcyberAuthor Commented:
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

0
 
aaaaaaCommented:
"wierd results"

what this mean?
0
 
royalcyberAuthor Commented:
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.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.