Use jQuery, try this:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(this).siblings("input:text").val("");
});
});
</script>
</head>
<body>
<div style="border: 2px solid red; margin: 10px">
<input type="text" value="apple"><br><br>
<input type="text" value="orange"><br><br>
<button type="button">Clear red block!</button>
</div>
<div style="border: 2px solid green; margin: 10px"">
<input type="text" value="pizza"><br><br>
<input type="text" value="burger"><br><br>
<button type="button">Clear green block!</button>
</div>
</body>
</html>
Read more:
jQuery Selectors[
^]