0

I have a form with few filed. Once i submit the form the data is stored in database and i will return to the same page. Now, How to clear the fields in the form in jsp??

<form class="form-horizontal col-lg-8" action="addDonationCamp" method="GET">
    <div class="form-group">
        <label for="location" class="col-sm-3 control-label">Location</label>
        <div class="col-sm-8">
            <input type="text" name="location" class="form-control" id="location" placeholder="Location" value="${fn:escapeXml(param.location)}">
            <label class="errorColor">${message.location}</label>
        </div>
    </div>
     <div class="form-group">

    <div class="form-group">
        <label for="description" class="col-sm-3 control-label">Description</label>
        <div class="col-sm-8">
    <div class="form-group">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="submit" class="btn btn-default">Submit</button>
        </div>
    </div>
</form>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
pradip
  • 3
  • 1
  • 3

2 Answers2

1

Reset doesn't reset all fields, everytime.

You can have something like this if you are using pure Javascript,

var formElements = document.getElementById("myForm").elements;
var fieldType = "";
for (i = 0; i < formElements.length; i++)
{
    fieldType = formElements[i].type.toLowerCase();
    switch (fieldType)
    {
    case "text":
    case "password":
    case "textarea":
    case "hidden":
        formElements[i].value = "";
        break;
    case "radio":
    case "checkbox":
        if (formElements[i].checked)
        {
            formElements[i].checked = false;
        }
        break;
    default:
        break;
    }
}
Nielarshi
  • 1,126
  • 7
  • 11
0

Simply use the following piece of code,

$('#myform')[0].reset();

myform would be your form id. And plese refer this link

Community
  • 1
  • 1
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34