JavaScript
window.onload = function(){
var span = document.getElementsByClassName('clear'), i;
for(i = 0; i < span.length; i++){
(function(i){
span[i].onclick = function(){
span[i].parentNode.getElementsByTagName('INPUT')[0].value = '';
};
})(i);
}
};
HTML
<form>
<div class="wrapper">
<input type="text" name="firstname" value="" class="textbox" />
<span class="clear">x</span>
</div>
<div class="wrapper">
<input type="text" name="lastname" value="" class="textbox" />
<span class="clear">x</span>
</div>
</form>
CSS
.clear{
position:absolute;
top:2px;
right:5px;
cursor:pointer;
}
.textbox {
width:100%;
}
.wrapper {
width:200px;
position:relative;
}
Working jsBin
A sidenote to the other answers: Assuming that there's only one element and using getElementById('clear')
isn't a good idea.