asp.net + javascript.

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
I have some javascript that takes data that is being typed into a html text area, and counts the number of characters entered on the keyup event of the textarea. I currently have set the maximum number of characters to a default value in code, ideally I need that value to be easily changed depending on who the user is.

I know that I can change the value be introducing a query string variable and examining that variable each time. However I feel that this option is unsafe as the individual user can simple alter the value at random.

I have tried to use a textarea, by setting the value in the textarea on the page load event, and then passing the name of the textarea to the javascript on the keyup event of the message textarea. However, when the javascript starts executing, I get an undefined event error. Any suggestions on how I can solve this problem.

The javascript method:
Code:
function limitText(limitField, limitCount, msgCount, charsCount, txtbox){
}

The onkeyup event of the message box:
Code:
onKeyUp="limitText(this.form.txtMessage,this.form.count,this.form.MsgNo,this.form.CharsLeft,this.form.sponsor);"

Mike55.
 
Dude....

How about this...

<textarea maxLength="300">

You have your textarea element...and a custom attribute of maxlength...
on the server side, just figure out the user's custom setting and set that value

<textarea maxLength=<%=textLength%> >

...Server code:

protected int textLength;

private void Page_Load
{
if (user is admin)
textLength = 1000;
else
textLength = 100;
}



Anyway, if you just want to solve your current problem...check for arguments inside the limitText function. You are most likely receiving an undefined error because the function is being ran before one of the params is populated.

limitText(...)
{
if (arguments.length < 5) return;
}
 
Back
Top