wood burning stoves 2.0*
The moose likes JSF and the fly likes Having trouble calling functions in js from jsf inputtext onclick Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Having trouble calling functions in js from jsf inputtext onclick" Watch "Having trouble calling functions in js from jsf inputtext onclick" New topic
Author

Having trouble calling functions in js from jsf inputtext onclick

joe vasher
Ranch Hand

Joined: Nov 06, 2009
Posts: 37
Hello, I am using a <h:inputtext ... > to capture a userid, and the default text in the window is UserID So what I was trying to do is use the onclick="myjavascriptfunction();" to call a function to clear the default text. I have not gotten to the point where i can test out the code to do this. because I cannot get the onclick attribute to call a javascript function. it works fine if I call something like submit() or alert() but it seems it can't find or won't find a function i right. Here is the two code samples i'm using to do this.

I was writing a backing bean to try and do this but not having any luck.

Thanks in advance for any help.


THis is the loginbar.jsp which is called by the next file inside a <f:subview>



THis is welcomeJSF.jsp

Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 79

You do not need valueChangeListener alone. If you put it then I'd recommend adding ajaxForFaces or RichFaces support and define the action tag inside the inputText:


If don't, just use the onclick or any other appropriate event to call the javascript function where you should access the field by its id and set its value to empty string. Here goes another problem - getting correctly the id. Check this thread, it has a couple of quick solutions to do this.


Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
willCodeForFood("Java,PHP,C#,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39
<script type="javascript"> should be:

either

XHTML


or simply

HTML



or rarely now, browser specific




and finally function clearTextMsg(){... // generally something like this.value passed to formref her inside the event-attribute on the element

should be (NOTE:put this below the form end tag , not up the top)


with



...did you have the fish?!............................ No.
joe vasher
Ranch Hand

Joined: Nov 06, 2009
Posts: 37
Fantastic, that fixes the problem of calling function. However I did some searching for page prefrix but can not find a reference to that. (getElementById("WHATTHEPAGEPREFIXED:userid") ) The one article i found on that told me to use this.Form (which doesn't work) in my above example. Can you provide a link to read about the PAGEPREFIXED how to get that value?

THanks

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble calling functions in js from jsf inputtext onclick