I have some code where I am creating an array of textareas based a number of items. So there could be anywhere from 1 and up...
I also want to limit the amount of text that can be entered into the text areas.
I found some code on http://www.mediacollege.com/internet/ja ... cters.html to do that...
but it doesn't seem to be working with the array of textareas.
Right now for testing, i am having it just use 1 textarea. So when i change the name so that it does a "name_1" instead of "name[1]" the javascript works just fine... Thing is... there are so many places where i am alreadying accessing the textareas as arrays, and I just don't want to change it all.
If there is a way to allow me to use the variabled textareas, I will greatly appreciate all the help i can get.
But if that isn't possible... I thank you all anyway.
Thanks in advanced.
javascript with input arrays...
Moderator: General Moderators
- J_Iceman05
- Forum Commoner
- Posts: 72
- Joined: Wed Aug 03, 2005 10:52 am
- Location: Las Vegas, NV
- J_Iceman05
- Forum Commoner
- Posts: 72
- Joined: Wed Aug 03, 2005 10:52 am
- Location: Las Vegas, NV
Javascript function coding
Textarea (and counter) coding
So, i have the textarea array (where i am limiting the number of characters)
and the input box array (where i am displaying the number left)
... I can put "this" in reference to the text area... but what should i do about the input box that says how many chars are sill available?
(as it won't work if either are arrays)
Code: Select all
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}
</script>Code: Select all
<textarea name="limitedtextarea[1]" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,100);"
onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,100);">
</textarea>
You have <input readonly type="text" name="countdown[1]" size="3" value="100"> characters left.</font>and the input box array (where i am displaying the number left)
... I can put "this" in reference to the text area... but what should i do about the input box that says how many chars are sill available?
(as it won't work if either are arrays)
try something like this:
untested:
untested:
Code: Select all
<script language="javascript" type="text/javascript">
limitNum = 15;
function limitText(limitField, limitCnt)
{
limitCount = document.getElementById(limitCnt);
if (limitField.value.length > limitNum)
{
limitField.value = limitField.value.substring(0, limitNum);
}
else
{
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
<body>
<input type="text" name="Leftsample[1]" id="leftsample[1]" value="15"><br>
<textarea name="sample[1]" onKeyDown="limitText(this,'Left'+this.name)"></textarea>
</body>- J_Iceman05
- Forum Commoner
- Posts: 72
- Joined: Wed Aug 03, 2005 10:52 am
- Location: Las Vegas, NV