0

In my javascript code, I want to clear the text fields after done with the operations using onclick command. Question: Is there a predefined fuction to serve this purpose?

5
Contributors
5
Replies
21
Views
1 Year
Discussion Span
Last Post by hastings.george.5
0

If you're using JQuery, something like
$(this).closest('form').find("input[type=text], textarea").val("");

0

If the initial values when the page is parsed are blank, you can use the .reset() method of the FORM (not the individual inputs), which should revert everything back to what the values were at page render.

If you don't have a form, or are looking for a specific input to reset, (as stated above) you simply have to get the input field and set the value to ""

0

if it is a <textarea>, in javascript you can go:
document.getElementById("textarea1").innerHTML = "";
This sets the inner HTML of the textarea to nothing, as textareas contain things by the standard <textarea>lorem ipsum</textarea>
But, if it is an <input type="text" /> tag, this is harder. try:
document.getElementById("input1").value = "";
The .value affects the value element of an input tag, and this clears it by setting it to "".

(Which is pretty much what ryantroop said)

Edited by mblan180131

0

hi nblan180131,

if it is a <textarea>, in javascript you can go:
document.getElementById("textarea1").innerHTML = "";

using document.getElementById("textarea1").value = ""; works perfectly for textarea.

Hi hastings.george.5,
I would suggest you use the reset button for form on HTML, since you would probably have more than one text field.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.