<script type="text/javascript">
var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery;
</script>
<input name="battery" type="hidden" value="">
<script type="text/javascript">
document.getElementsByName("battery")[0].value = battery.level;
</script>
this only works if your input is the first with the name battery. If you can give it an id (the input), you can use document.getElementById("id"), wich always exactly returns one element; multiple elements with the same id are not "allowed".