This topic is locked

add text area character counter on edit/add page

9/4/2009 5:22:32 PM
ASPRunnerPro General questions
L
leizleho author

Hi,

I want to add a text area counter on every text area field I have.

I already have a javascript function for this and the next thing I need to do is to insert this attribute in text area tag:
onKeyDown="textCounter(document.editform.value_application,document.editform.txtcnt,300)"

onKeyUp="textCounter(document.editform.value_application,document.editform.txtcnt,300)"
how can I do this programmatically?
Thanks,

rochzle

Sergey Kornilov admin 9/6/2009

rochzle,
sure, here is an example:



<script>

fieldname_value.onkeydown = function () {

textCounter(document.editform.value_application,document.editform.txtcnt,300)

};

</script>
L
leizleho author 9/10/2009



rochzle,
sure, here is an example:



<script>

fieldname_value.onkeydown = function () {

textCounter(document.editform.value_application,document.editform.txtcnt,300)

};

</script>



Hi Sergey,
I tried your code above but I couldn't make it work.

this is the html code, it's so simple but I am having a pain to implement it in asprunner. Appreciate your help. thanks.
<body>

<script LANGUAGE="JavaScript">

function textCounter(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="myForm"

action="/articles/articles/javascript/dynamictextareacounter.asp?ID=<%=siteID%>"

method="post">

<textarea name="message1" wrap="physical" cols="28" rows="5"

onKeyDown="textCounter(document.myForm.message1,document.myForm.remLen1,125)"

onKeyUp="textCounter(document.myForm.message1,document.myForm.remLen1,125)"></textarea>



<input readonly type="text" name="remLen1" size="3" maxlength="3" value="125">

characters left



<textarea name="message2" wrap="physical" cols="28" rows="5"

onKeyDown="textCounter(document.myForm.message2,document.myForm.remLen2,125)"

onKeyUp="textCounter(document.myForm.message2,document.myForm.remLen2,125)"></textarea>



<input readonly type="text" name="remLen2" size="3" maxlength="3" value="125">

characters left



<input type="Submit" name="Submit" value="Submit">



</form>
</body>

Sergey Kornilov admin 9/10/2009

rochzle,
I'm not really sure how this applies to ASPRunnerPro.