first of all convert the value of cost salary and cost ahead into the integer .
and add it.
like that in java script
document.getElementById('totalcost').value=total;
var salary=document.getElementById('cost salary').value;
var ahead=document.getElementById('cost ahead').value;
var total=parseInt(salary)+parseInt(ahead);
after that set the value in total like that
document.getElementById('totalcost').value=total;