joymis Posted November 27, 2016 Share Posted November 27, 2016 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 More sharing options...
dsonesuk Posted November 27, 2016 Share Posted November 27, 2016 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; 2 Link to comment Share on other sites More sharing options...
joymis Posted November 27, 2016 Author Share Posted November 27, 2016 Hi, dsonesuk Thank you for your help, It's work. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 29, 2016 Share Posted November 29, 2016 You also have an alternative option instead of using default value in value attribute, use default value in placeholder attribute, then you clear the value completely as empty string "", instead of using .defaultValue. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now