Jump to content

How to reset some text field


joymis

Recommended Posts

Hello, everyone

Assume I have the following some code

<form>
...
<tr>
  <td>
    <button type="button" onclick="EditReset(0)"></button>
    <input type="text" class="edit_file_name" value="123">
  </td>
</tr>
<tr>
  <td>
    <button type="button" onclick="EditReset(1)"></button>
    <input type="text" class="edit_file_name" value="abc">
  </td>
</tr>
...
</form>

<script>
function EditReset(index){
    // what kind of method can do it
}
</script>

when I edit 1st row input change '123' to '123edit'

 

and edit 2nd row input change 'abc' to 'abcedit'

 

and then I click button ( EditReset(0) ), how can I do reset '123edit' to '123' but 'abcedit' will not be reset

 

because I don't want to use form.reset() reset all, have any method can do it?

Thank you

Link to comment
Share on other sites

use EditReset(this), 'this' will mean when clicked that it will be a reference of element clicked.

 

function EditReset(elem) 'elem' will be the element clicked.

 

You then go to parent element (tr) of the element clicked, and transverse down to find first input

elem.parentNode.getElementsByTagName('input')[0]

You then reset that inputs value to the default value the input has on loading using .defaultValue

elem.parentNode.getElementsByTagName('input')[0].value = elem.parentNode.getElementsByTagName('input')[0].defaultValue;
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...