Can someone explain to me why I cannot use document.getElementById('id').value inside of a function?
I was trying to make a simple multiplication script (im learning JS, its actually kinda fun) and realized quickly how annoying typing that whole line of code just to return a value is, so I wrote a small function:
<script type="text/javascript">
function value(elementid){
return document.getElementById(elementid).value
}
</script>
However, this does not function and will simply break my whole script's functionality. I wanted to simply type value('id') to return the value of the element.
To fix it, a friend suggested I take out the .value in the function and add it to the end of each line where I call the function instead, like value('id').value.
Why didn't my first way work?
Thanks for the help!