Set value of hidden field in a form using jQuery's ".val()" doesn't work
:text
will fail for a input with a type value of hidden
. It's also much more efficient to just use:
$("#texens").val("tinkumaster");
ID attributes should be unique on a web page, make sure yours are as this may contribute to any problems you're having, and specifying a more complicated selector just slows things down and doesn't look as neat.
Example at http://jsbin.com/elovo/edit, using your example code at http://jsbin.com/elovo/2/edit
If you're having trouble setting the value of a hidden field because you're passing an ID to it, this is the solution:
Instead of $("#hidden_field_id").val(id)
just do $("input[id=hidden_field_id]").val(id)
. Not sure what the difference is, but it works.
Finally, I have found a solution and it's a simple one:
document.getElementById("texens").value = "tinkumaster";
Works like a charm. No clue why jQuery does not fall back to this.