Clearing all elements in the form in javascript

How I can clear (reset) all the elements in the document in javascript?
I tried the following and none of them worked:

I am sure there should be a way.
Thanks for all.

There is no such method as refresh. What is your use-case?


In the below document which is used to do clearance (payment settlement) with the drivers, when selecting the driver, the data in the upper side (red rectangle) will be fetched, then the user has to select clearance date and click on Get Data to fill the data in the lower part (below green rectangle).

Until now, every thing is fine.

If need to select another driver, so the data in the upper side will be fetched. But in this case, the below data (in the green rectangle) is related to the previous driver and that is wrong, it should be cleared (becoming blank), and when the user select the new data and click on Get Data, then the corresponding data for the new driver should be fetched in the below part.


You can clear individual fields by using frm.set_value('fieldname', '')

This for certain field, I need to clear all fields in the form.
Actually what I need to do when selecting the Employee is to store the selected value first and then clearing all fields and then re-assign employee value (from the stored value) and then I will fetch the needed values based on the Employee value.


In HTML for example, there is Reset button that clear all the form.
I as asking about same thing equivalent to be used in .js in erpnext.


The only alternative I can think of to @rmehta’s answer is to call .each() on fields_dict which is dangerously lazy. I think you want the control afforded by setting each of the fields to ""with a cur_frm.set_value() call.

As for what you’re actually trying to do, this sounds like a classic callback structure. Store a value (into the database, which implicitly means a callback structure, though the function may have been written as a helper by the Frappe team so part of it is obscured from you), do a lookup based on that value (again a database call) and then populate a from with the returned values.

I don’t know what you mean by “in HTML”, it’s too general a context.

I think he means in HTML, you can add a button of type “reset” which will automatically clear all the other fields in the HTML <form> .

Eg. in the code below, if you click the reset button, the fname and lname fields will get cleared.

<form action="/action_page.php" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <button type="submit" value="Submit">Submit</button>
  <button type="reset" value="Reset">Reset</button>
1 Like

Exactly, this is what I meant.
So how can we do same thing in ERPNext but instead of having Reset button, how it is possible to be done through script depending on the need?

You can add a reset button using frm.add_custom_button api