• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having trouble calling functions in js from jsf inputtext onclick

 
joe vasher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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

 
joe vasher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic