A demo for sharing data between an input (id=obHid) and a textarea (id=idField)
if($.browser.msie)
$("#"+idField).text($("#obHid").val()); // IE
else
$("#"+idField).attr("value", $("#obHid").val()); // FF
Iskrahelk,
A demo for sharing data between an input (id=obHid) and a textarea (id=idField)
if($.browser.msie)
$("#"+idField).text($("#obHid").val()); // IE
else
$("#"+idField).attr("value", $("#obHid").val()); // FF
Iskrahelk,
Don't use either of those methods, and especially don't use browser sniffing. Touching $.browser
is almost always a mistake.
The proper way to read and write form field values in jQuery is val()
. It doesn't matter whether the form field involved is an <input type="text">
or a <textarea>
, they'll both work the same.
$('#'+idField).val($("#obHid").val());
[Aside: however this will break if idField
may contain dots, as in a selector string they'll turn into class selectors. If that's a concern just use the plain JavaScript version:
document.getElementById(idField).value= document.getElementById('obHid').value;
a bit wordier, but more straightforward.]