I found on some examples on the web that people were passing the form to a function and then they were only using the id of the item to access it like in :
<form id="frm">
<input type="text" id="textbox" name="textbox" value="some value" />
</form>
<script>
console.log(getelementval("#frm"));
function getelementval(frm) {
return frm.textbox.val();
}
</script>
But FireBug tells me that frm.textbox is undefined… Then I’m searching why it doesn’t work on the net but I didn’t find anything explaining this option and how to use it.
Any clues?
You will have to modify the JS slightly to make this work:
Demo: http://jsfiddle.net/gdZEK/2/
$(frm)returns an element matching the selector.[0]fetches the actual DOM element..textboxworks on DOM elements only, not jQuery objects. It matches[name='textbox']..valueneeds to be used instead of.val(), as.textboxisn’t a jQuery object.Honestly, I don’t really see how this is better than just using jQuery: