Reputation: 33
I am going to get the value from the HTML TextArea , it is working perfectly until i put runat="server" on the control.
<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>
then this is the Body
<div runat="server">
<%-- Note:Set runnat="server" --%>
<textarea runat="server" name="limitedtextarea" id="Area" onkeydown="limitText(this.form.limitedtextarea,this.form.countdown,100);"
onkeyup="limitText(this.form.limitedtextarea,this.form.countdown,100);" >
i am trying to put the value (of textArea) into a variable, then show it on a label
i really appreciate your help..thanks..
Upvotes: 1
Views: 279
Reputation: 2325
You can directly send the control reference using this
keyword and in javascript function use that reference with value to check the limit.By this you can use the same function with may other controls.
<textarea runat="server" name="limitedtextarea" id="Area"
onkeydown="limitText(this,this.form.countdown,100);"
onkeyup="limitText(this,this.form.countdown,100);" >
<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>
Upvotes: 0
Reputation: 6330
When you make any control server side control by using runat=server
then the ID of that contol get changed,
now you can get the server side control ID in Javascript by using ClientID like
document.getElementById('<%=Area.ClientID%>')
Upvotes: 1
Reputation: 136104
When you add a runat="server"
it will change the name of the form elements within, and you're relying on the form having named elements:
this.form.limitedtextarea
For the textfield, you should be fine to pass just this
, for the countdown
you could use an id:
onkeydown="limitText(this,document.getElementById('countdowntimer'),100);"
Upvotes: 0