Jump to content

function validar not accepted when "validating HTML code"


breaststroke

Recommended Posts

Hello!How are you, I am trying to validate my HTML code and I am getting some errors. Some are concerning Javascript.I think we can use Javascript when validating HTML, can´t we?. (I am usig webdeveloper on Mozilla).I have a textarea in a form. I want it to have a maximun number of characteres. I have tried to do that through php but I don´t think it is possible in a textarea. I would be happy if someone told me a way to get that with php!This is the function I am using:<script type="text/javascript">function validar(e,obj) { tecla = (document.all) ? e.keyCode : e.which; if (tecla != 13) return; filas = obj.rows; txt = obj.value.split('\n'); return (txt.length < 20);}</script>That part doesn´t give me any errors back, but the following does:<textarea name="reasons" rows="13" cols="50" onkeypress="return validar(event,this);" onkeyUp="maximo(this,700); padding=10px;" onkeyDown="maximo(this,700);" value="$reasons">$reasons</textarea>I don´t have any idea what´s wrong with this script. Maybe it is just a not valid script. Could anyone tell me, please, a solution to make this valid or how to use another script(if it were php the better, hehe)?.Thank you very much in advance!!RegardsP.S. Sorry , I forgot to say the script works. What happens is that I get an error when I try to validate it(through webdeveloper).

Link to comment
Share on other sites

What is the error? Textarea elements do not have a value attribute.
hi justsomeguy,thank you, you are right, now it gives me fewer errors. I knew I wasn´t using the "value " attribute, but I forgot to take it away.It is strange, because I have two textareas on the same page. They are basically the same.Now only one gives errors. The script is exactly the same for both. (what I wrote above. Only the figure(500 for one, 700 for the other) changes).This is what I get:"there is no attribute onkeyDown""there is no attribute onkeyUp"regards
Link to comment
Share on other sites

It wants the attributes to be all lowercase.
yes!!it works, thank you so much. And what a great way to solve it!May I ask you another question related to this?. Would you know any way to limit the number of characteres in a textarea through php?. It doesn´t exist, right?.The matter is that the user can disable javascrip, and I wouldn´t like to get textareas with three thousand characteres, for example.Thanks againRegards
Link to comment
Share on other sites

PHP can trim the string once it gets submitted, but it can't limit it in real time as they type.
Thank you justsomeguy,Then I suppose we can trim it on the database. And also validating the textarea by strlen, for example. I hadn´t thought about this possibility before. Thank you so much, and regards!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...