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

Posted on 2006-04-21
Last Modified: 2010-04-01
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>
Question by:royalcyber
    LVL 23

    Accepted Solution

    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.
    LVL 9

    Assisted Solution

    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();

    Author Comment

    Actually this is the code which I am looking for


    <% 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


    LVL 4

    Expert Comment

    "wierd results"

    what this mean?

    Author Comment

    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.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    handling Struts tag, JSTL tag and scriptlet in Ajax. 7 157
    maven scope 1 117
    AlarmClock Challenge 35 143
    How to set default webapp for host 6 38
    Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now