7

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
  • Haha Joint Strike Fighter. ;-) Commented Apr 19, 2011 at 11:04

3 Answers 3

6
  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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

2

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

1 Comment

Default is "submit" and you don't need to give it, if type is given in tag it will check for value "submit" or "reset" and if it is not equal what it expects it will not submit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.