[jboss-user] [Beginners Corner] - JBOSS SEAM and JavaScript
andipesel88
do-not-reply at jboss.com
Mon Feb 19 07:57:15 EST 2007
Hello to everyone!
I'm a bloody Jboss novice - the only thing already now are Java itself and JSP's.
Right now I need to learn JBOSS Seam in connection with hibernate for a school project.
The installation and development of my project is fine, everything works.
But my problem is the following:
I need a javascript on my site. I know that there is the possibility of using AJAX and JSF components, but I've found nothing that matches my need.
I need a counter which counts from e.g. 160 down to 0 in an inputText depending on how many characters the users has written in the textarea.
So I thought that it might work if I put the javascript itself hardcoded onto my site - but it doesn't. There is no error message or anything else that is shown. The JavaSCript itself works fine in a normal HTML site.
So here is my code:
I've a template.xhtml where i puttet the javascript between the header tags:
...
| <script type="text/javascript">
|
| <![CDATA[
| function pruef (chars) {
| var anz=0, len=0,s;
| var msg = document.predefines.predefines:nachr.value;
|
| if (!chars) {
| chars = 151;
| }
| for (var i=0; i < msg.length; i++) {
| s = msg.charAt(i);
| if (s=='?' || s=='~' || s=='^' || s=='\\' || s=='{' || s=='}' || s=='[' || s==']' || s=='|') {
| if (anz>(chars-2)) {
| break
| };
| anz+=2;
| } else if (s=="\r") {
| } else {
| if (anz>(chars-1)) {
| break
| };
| anz++;
| }
| len = i+1;
| }
| if (msg.length> len) {
| document.predefines.predefines:nachr.value = msg.substring(0,len);
| }
| document.predefines.predefines:num.value = chars-anz;
| if (navigator.appName =="Netscape" && parseInt(navigator.appVersion) <= 4){
| document.captureEvents(Event.KEYPRESS);
| document.predefines.predefines:nachr.onkeypress = pruef;
| }
| }
| ]]>
| </script>
| ...
|
and then i just called the function on the site i need:
| ...
| <h:form id="predefines">
| ...
| <h:panelGroup>
| <h:inputTextarea id="nachr" onkeyup="pruef(160);" cols="50" rows="5"/>
| <h:inputText value="160" id="num" onfocus="this.blur();"/>
| </h:panelGroup>
| ...
| </h:form>
| ...
|
I hope you can help me!
andy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4018791#4018791
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4018791
More information about the jboss-user
mailing list