Click to See Complete Forum and Search --> : <h:inputTextarea> text count problem


barantamer
01-20-2009, 08:26 AM
hello i am trying to restrict the number of characters to be entered to textarea in my jsf page on the client side

i am trying to use the codes below

<SCRIPT LANGUAGE="JavaScript">
// function parameters are: field - the string field, count - the field for remaining characters number and max - the maximum number of characters
function CountLeft(field, count, max) {
// if the length of the string in the input field is greater than the max value, trim it
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
// calculate the remaining characters
count.value = max - field.value.length;
}
</script>


<h:inputTextarea onkeyup="CountLeft(this.form.txtAreaStream,this.form.left,50);" onkeydown="CountLeft(this.form.txtAreaStream,this.form.left,50);" id="txtAreaStream" cols="50" rows="10" required="true" >


Actually i have found the problem but i do not know how to solve it since i am new to jsf

The HTML output is

<textarea name="j_id_jsp_1552126572_1:txtAreaStream" id="j_id_jsp_1552126572_1:txtAreaStream" cols="50" rows="10" onkeydown="CountLeft(this.form.txtAreaStream,this.form.left,50);" onkeyup="CountLeft(this.form.txtAreaStream,this.form.left,50);"></textarea>


the name of the text area is changes. How can i solve this problem?

Thanks in advance

chazzy
01-20-2009, 06:08 PM
what jsf library are you using?

barantamer
01-21-2009, 05:05 AM
Myfaces with tomahawk

chazzy
01-21-2009, 07:15 AM
i think you should then use a t:inputTextarea with forceId and set the id that way. then the id you assign it in your jsf tag will get populated and you can pull it up that way. there's no way i can think of to force the name though.

barantamer
01-21-2009, 08:44 AM
Html output is below

<textarea name="j_id_jsp_1552126572_1:j_id_jsp_1552126572_12" id="j_id_jsp_1552126572_1:j_id_jsp_1552126572_12" cols="50" rows="10" onkeydown="CountLeft(this.form.txtAreaStream,this.form.left,50);" onkeyup="CountLeft(this.form.txtAreaStream,this.form.left,50);"></textarea>

I am not sure how this is going to help me?

barantamer
01-21-2009, 08:55 AM
so sorry ,
it looks like i didnt use it correctly before. It works thanks.

By the way , it also fixes the name


textarea name="txtAreaStream" id="txtAreaStream" cols="50" rows="10" onkeydown="CountLeft(this.form.txtAreaStream,this.form.left,50);" onkeyup="CountLeft(this.form.txtAreaStream,this.form.left,50);"></textarea>

chazzy
01-21-2009, 06:17 PM
maybe you could also post your final t:inputTextarea so that it could help others?

barantamer
01-22-2009, 12:12 AM
Sure


<t:inputTextarea id="txtAreaStream" forceId="true" onkeyup="CountLeft(this.form.txtAreaStream,this.form.left,100);" onkeydown="CountLeft(this.form.txtAreaStream,this.form.left,100);" cols="50" rows="5" required="true" >
</t:inputTextarea>


this.form.left is a read only inputtextarea which shows the number of characters left.