Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

submit based on the Javascript function called via onclick attribute in <h:commandbutton>  RSS feed

 
hemamalini nithyanandam
Ranch Hand
Posts: 53
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a form i used <h:commandButton> i called a Javascript function. Though the function returns false , form is submitted and action method is called.

i used like this

<h:commandButton onclick="test();" action="{#bean.menthod}">

test- javascript method returns boolean value false.

Above doesnt work. Below mentioned code alone worked. I want to know why

<h:commandButton onclick="if(test) return true;else return false" action="{#bean.menthod}">
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because your first example doesn't explicitly return anything to the HTML javascript processor.

This would work, though:

 
hemamalini nithyanandam
Ranch Hand
Posts: 53
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in test() method i used return false also. i want to know why result of test is not returned to the component though the test() method returns false. What should i include in that javascript function
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't returned to the component. It works solely on the client but the component is located on the server.

And the "return" is required to pass the function's result to the client onclick processor code. Otherwise the value of the function is simply dropped.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!