How do I get this done. I am trying to append text to a text area. If some value already exists then append. I had it working but seems like it cannot work in all browsers. Is there a better way to do this?
Tried both ways, they don’t work in Chrome, IE and FF –
if ($('#log').value == undefined) {
$('#log').val("First: " + result[0]);
} else {
$('#log').val($('#log').value += "Second: " + result[0]);
}
if ($('#log').value == undefined) {
$('#log').val("First: " + result[0]);
} else {
$('#log').val(log.value += "Second: " + result[0]);
}
Without If, this works in Chrome but not in IE and FF –
$('#log').val(log.value += "First: + result[0]);
jQuery objects don’t have a
.valueproperty, so$('#log').valuewill always beundefined. This means that your statement will always call$('#log').val("First: " + result[0]);and never call the second one.You need to check
if($('#log').val() == '')instead.As for
.val(), you can pass a function. This function will be passed the current value of the input.