Reset button for specific fields

I have a working form that generates a string, and by clicking on the button, it places the string in the text area field.

I also have a reset button that allows all fields to be reset, but not a text area with strings.

Here is my code.

HTML:

<form> <!--some more code and inputs--> </tbody> </table> </p> <p> <input value="Generate URL" onclick="createURL1();" type="button"> <input name="result" size="70" class="clearit" type="text" ></input> <input type="button" value="Add The Link" onClick="addtext();"></p> <textarea id="t5" style="width:600px;" name="outputtext" ></textarea><br><br> </p> </td> </tr> </tbody> </table> <input type="reset" value="Clear" id="reset" ></input> 

JavaScript:

 $(document).ready(function(){ $('#reset').on('click',function(e){ e.preventDefault(); $('.clearit').val(""); }); }); 

I gave all the inputs that I want to reset for the class (clearit), and the reset button got the identifier: reset. The only field in which I did not want to be reset received a different identifier.

it should work, but it doesn’t .. Please help :)

0
source share
1 answer

use this javascript function and exclude the element with the identifier that you do not want to use reset, and you can specify the reset method as either empty left or drop-down value equal to -1 and it works on IE and fire fox tesed

  function resetLabels() { //mainForm is the name of form var cells = document.mainForm.elements; for (var i= 0; i < cells.length; i++) { if(cells[i].name !='txtName')//for example to not reset by name cells[i].value=''; // cells[i].className = ''; // cells[i].style.color = 'black'; // or cells[i].value='-1' for drop down // or cells[i].name= ''; name and id to compare and exclude specific elements // or cells[i].id= ''; //and i suggest to name like txt... and ddl...to //know the type by name and id or just check the type //of element by using cells[i].type } } 
0
source

Source: https://habr.com/ru/post/1208225/


All Articles