Saturday, April 24, 2010

'value.length' is null or not an object error in IE browser?

Here is the code:



1) HTML code:



%26lt;body onload="updateAll(); initPreview()"%26gt;



...



%26lt;div%26gt;



%26lt;em class="field-count"%26gt;%26lt;span id="titleCounter"%26gt;75%26lt;/span%26gt; ".SUBMIT_VIEW_LEFT."%26lt;/em%26gt;



%26lt;label for="title" accesskey="2"%26gt;%26lt;/label%26gt;



%26lt;input type="text" id="title" name="title" value="" maxlength="75" class="form-text-variable" /%26gt;



%26lt;/div%26gt;



2) js code:



function initPreview() {



setInterval('updateAll()',1000);



}



function updateAll()



{



$('titlepreview').innerHTML=$('title').v...



charCounter($('title'),75,$('titleCounte...



}



function charCounter(field,maxLength,countTarget) {



==%26gt; var inputLength=field.value.length;



if (inputLength%26gt;=maxLength) {



field.value=field.value.substring(0,maxL...



}



countTarget.innerHTML=maxLength-field.va...



}



Somehow, the above code works in FF, but not in IE I always have an error: 'value.length' is null or not an object. at line ==%26gt; in function charCounter()



please help, it is very urgent.



thanks,



-xun



'value.length' is null or not an object error in IE browser?windows update





Well, your code was truncated so I cant debug it myself. But try this:



var inputLength = (field %26amp;%26amp; field.value %26amp;%26amp; field.value.length ? field.value.length : 0);



Though it looks like your field is not being set/passed correctly. Be sure you are using the right ways to find it (document.all, getElementById, etc) according to browser versions, etc.



'value.length' is null or not an object error in IE browser?microsoft excel internet explorer



try using a validator

No comments:

Post a Comment