you are not updating the score field.try this
function doFunction(ref)
{
score =document.getElementById("1").value;
if (ref.value== "X")
{
randnum=Math.floor( 9*Math.random() ) + 1;
ref.value=randnum;
score = parseInt(score + ref.value, 10);
document.getElementById("1").value = score;
}
}
also you have to change the first alert to
if(score > 21)
{
window.alert ("You hit " + score + " You have lost");
}