lilster143
03-07-2006, 01:12 PM
I'm working on a database where I need to limit a Memo field to 1900 characters. Any ideas on how to go about doing this? I would to display a message box once 1800 characters have been reached and then let the user continue to 1900 and then have "beep" sound...thus telling the user that the maximum number of characters has been reached.
lmf232s
03-07-2006, 06:00 PM
java script.
I think i have alittle something that might work. I did this some time back so it could use an update and i have only tested this in IE, We dont use anything else here.
First off i add this little think next to the memo field. You dont have to add it but what it does is diaplay the total number of characters allowed and then updates as you type to show you how many characters you have left.
<font color="red">Max (<input type="text" name="txtCountDP" id="CTRCOM" value="500" size="3" style="BACKGROUND-COLOR: lightgrey; TEXT-ALIGN: center;border=0;">)</font>
Then this is my textarea
<textarea rows="4" cols="40" name="txtComments" onkeyUp="Count(this, 'CTRCOM', 500);"><%=txtComments%></textarea>
What fires here is the onKeyUp event, it passes it a referece to the object (this), the id of counter (First piece of code i pasted, notice its id="CTROCOM", this can be anything, that just refered to the field i was using it for), and then the 3 arguement is the max length.
Then this is the function i call and do all the checking
function Count(obj, counter, Max){
var mycount = obj.value;
var MaxValue = Max;
if(mycount.length >= MaxValue){
obj.value = mycount.substring(0, MaxValue);
document.getElementById(counter).value = MaxValue-mycount.length;
}else{
document.getElementById(counter).value = MaxValue-mycount.length;
}
}
All together
<script language="javascript">
function Count(obj, counter, Max){
var mycount = obj.value;
var MaxValue = Max;
if(mycount.length >= MaxValue){
obj.value = mycount.substring(0, MaxValue);
document.getElementById(counter).value = MaxValue-mycount.length;
}else{
document.getElementById(counter).value = MaxValue-mycount.length;
}
}
</script>
<Body>
<form name=form method=post>
<table width="100%" class="clearbody">
<tr>
<td class="greyBG">COMMENTS: <font color="red">Max (<input type="text" name="txtCountDP" id="CTRCOM" value="500" size="3" style="BACKGROUND-COLOR: lightgrey; TEXT-ALIGN: center;border=0;">)</font>
</td>
</tr>
<tr>
<td>
<textarea rows="4" cols="40" name="txtComments" onkeyUp="Count(this, 'CTRCOM', 500);"><%=txtComments%></textarea>
</td>
</tr>
</table>
</form>
</body>