MDanz Posted May 24, 2011 Share Posted May 24, 2011 the following code doesn't work. If i change 'textarea[]' to just 'textarea' it works. But i need textarea in an array. <SCRIPT LANGUAGE="JavaScript"> function counter(field,cntfield,maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else cntfield.value = maxlimit - field.value.length; } </script> <form name="submitform"> <textarea name="textarea[]" cols="30" rows="1" onKeyDown="counter(document.submitform.textarea[],document.submitform.charleft,1000)" onKeyUp="counter(document.submitform.textarea[],document.submitform.charleft,1000)"></textarea> <br> <input readonly type="text" name="charleft" size="3" maxlength="4" value="1000"> characters left </form> Link to comment https://forums.phpfreaks.com/topic/237340-javascript-array-problem/ Share on other sites More sharing options...
Adam Posted May 24, 2011 Share Posted May 24, 2011 JS thinks it's an array instead of the (string) name of the element. What you can do in JS though is access object properties like an array, so instead of: document.submitform.textarea[] Use: document.submitform['textarea[]'] Link to comment https://forums.phpfreaks.com/topic/237340-javascript-array-problem/#findComment-1219615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.