Jump to content

javascript array problem


MDanz

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.