Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF CommandButton onclick does not call Javascript function

I am using a command button from JSF. I don't know why I can't call my javascript function. NO alert will show when I click the button.

<h:commandButton id="login" value="Login" action="login"
   onclick="return checkPasswords();" type="Submit" /> 

My Javascript function:

function checkPasswords() {
    alert("test");
    return false;
}
like image 994
cedric Avatar asked Dec 17 '09 11:12

cedric


2 Answers

  1. Check your generated code (open the page -> view source)
  2. Check your javascript console (Firefox) for errors
  3. make sure your function is callable from a normal <input type="button">
  4. lowercase your button type.

Otherwise, it should work - I have exactly the same piece of code in my current codebase that works perfectly.

like image 169
Bozho Avatar answered Nov 15 '22 09:11

Bozho


This is working

<script type="text/javascript">
function checkPasswords() {
   alert("test");
   return false;
}
</script>

<h:commandButton  id="login" value="Login" action="login"
             onclick="checkPasswords();" type="submit"/>
like image 26
baybora.oren Avatar answered Nov 15 '22 08:11

baybora.oren