I'm trying to have jQuery test the length of the text in the input box onLoad and change the size of the input box to fit. Here is my code attempt so far:
$("#emailSubject").attr('size', this.val().length);
I'm getting the following error:
this.val is not a function
What am I doing wrong?
Update: Now I'm no longer getting the first error, but the length is showing up as 0 even though it's not supposed to be. (I'm using an alert to check what the length is). Why would that be happening?
Update: Here is the code context:
$(
function()
{
//works correctly
alert($("#emailSubject").val().length);
//throws error
$("#emailSubject").attr('size', ($(this).val().length));
}
)
New error- the length is showing up correctly in the alert, but I'm getting the error:
Index or size is negative or greater than the allowed amount.