function recogeHora() { var IDdelTextfield = "hora" ; var hora = document.getElementById(IDdelTextfield ).value ;}<input type=button onClick="recogeHora()" value="Recoge Hora" />