1

In a webpage I am writing I want to be able to clear two text boxes when I click on either one of them. So far I have been able to clear one when I click the other, but it won't clear itself.

Here is my html/javascript so far:

<!DOCTYPE html>
<html>
<head>
<script>


function clear()
{
 var c = document.getElementById('c');
 c.value = '';
 var f =document.getElementById('f');
 f.value= '';
}


</script>
</head>
<body>

<input placeholder = "Celsius" id="c" onclick='clear()'></br>
<input placeholder = "Fahrenheit" id="f" onclick='clear()'></br>

</body>
<p>

</p>
</html>
TandyRayes
  • 55
  • 1
  • 9

1 Answers1

2

Rename your function clear to something else, otherwise you are calling the document.clear function

This answer by F. Kling might be useful to you

Community
  • 1
  • 1
Michel
  • 26,600
  • 6
  • 64
  • 69