Want to make a function to clear a text box using a button.

Here is what I have so far:

HTML:

<button onclick="clear()">Clear</button>

<form name="myForm1">
<textarea rows="4" cols="50" id="myTextArea" name="myTextArea">
</textarea>
</form>

JavaScript:

function clear() {
document.myForm1.myTextArea.value ="";
}


I don't really know what i'm doing if i'm honest. Is this close to what i need to do? I have to use JavaScript.

Thanks!