onmousedown commandbutton
Hi,
I have been trying to validate an input field with javascript using onmousedown="function();return false;" inside a commandbutton.
<h:commandbutton onmousedown="myfunc();return false;" action="mybean.x"/>
This works fine in internet explorer, but in firefox, the action method is still called, even if javascript validation fails.
anyone can help?
[388 byte] By [
kev9023a] at [2007-11-27 1:34:41]

# 1
Wrong, IE is failing hardly. Remove the "return false" and you'll see that the form is even not submitted.
Onmousedown/up events aren't intented for the actions you expected. Use onclick instead. And let the function return false or true and don't hardcode "return false;" in the onclick.
# 2
Hi,I now am using onclick="myfunc();"<h:commandButton onclick="myvalidator();" action="myBean.x"/>Despite the function myvalidator() returning false, the action method of the commandButton is still executed. I have tested in ie & firefox.any solution
# 4
Tried that.
It works in IE, but not in firefox (action method is called after clicking ok on alert)
My code is as follows.
validate(){
if(condition){
return false;
}
}
<body>
<f:view>
<h:form>
<h:commandButton onclick="return validate();" action="myBean.x"/>
</h:form>
</f:view>
</body>
# 5
Then your JavaScript is simply bad. Use the Web Developer Toolbar extension to check for any JS errors and/or use the Venkman JavaScript Debugger extension to debug the JS.
To prove that this should just work in FF: here is a simple example to try it out yourself:
<h:form>
<h:commandButton value="false" onclick="return false;" action="#{myBean.action}" />
<h:commandButton value="true" onclick="return true;" action="#{myBean.action}" />
</h:form>
MyBeanpublic void action() {
System.out.println("booh!");
}