I have a div, which contains a text input field:
<div id="age" class="fullScreen">
<input type="text" id="age" class="textInput" placeholder="Please enter age..." />
<button type="button" onclick="submitAge()">Submit</button>
</div>
submitAge() looks like this:
function submitAge() {
var ageVal = document.getElementById("age").text;
alert(ageVal);
}
But in Google Chrome and Webkit Nightly I see an alert with the text “undefined” (I can’t test in any other browsers because the page contains web-sockets).
The chrome developer tools show this:

I assume that the problem is that the input is not in a form, but I don’t want it to be in a form because I will be submitting the data via websockets.
Do I have to put it in a form or is there a better solution?
Thanks.
You have redefined the id “age”. Rename either your div or input and you should be fine.