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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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();
   %>
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

aaaaaaCommented:
"wierd results"

what this mean?
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.