开发者

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;
}


  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.


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"/>


Give s in lowercase in type="submit", The type attribute sets the type of button to create for this component. The valid values for this attribute are "submit" and "reset". The default value for this attribute is "submit".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜