How do I clear a hidden JSP field using javascript?

Posted on 2009-12-29
Last Modified: 2012-06-21
I want the user to be able to click on a hyper link that will clear the value in a hidden field.  
here i sm code
<TD  ><INPUT type="hidden" name="myField" value="initial value that i want to clear">
<LABEL id="myField" style="font-weight: lighter"></LABEL>

The javascript that I call currently does

When I submit the form, the field will come back blank but I want it to clear without having to go back to the server.
Question by:ltownbarry
    LVL 20

    Expert Comment

    by:Sathish David Kumar N
    write onblur or onchnge method function and set the value u mention retutn true
    then it wont go to server
    LVL 3

    Accepted Solution

    Few solutions

    1) Disabled values will not be posted to server.

    formName.formElement.disabled = true;

    2) Place all the hidden elements in a <div id="wantToClear">

    before submitting the form do the below operation,
    document.getElementById("wantToClear").innerHTML = ""; //Watch for proper syntax

    3) You can remove the form element like this..

        var elm = document.forms[0].elements[name];

    Hope that helps!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    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…

    759 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

    14 Experts available now in Live!

    Get 1:1 Help Now