function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mt0859mt0859 

Command button won't call javascript

Hi All,

 

I'm having a problem with my visual force page whereby i'm simply trying to get a command button to call a test javascript function, and it just doesn't want to play! i've managed to do it on other VF pages i have, but for some reason here it just won't work. Hopefully it's something dead simple that i've just missed because i've been staring at it for so long!

 

The page is of the form:

 

 

<apex:page controller="AController" extensions="AControllerExt" >
<apex:form id="form">
<h1>Some text here</h1>
</apex:form>
<apex:form>
<apex:outputLabel>Label text here</apex:outputLabel>
<br/>
<br/>
<apex:commandButton value="ButtonText" onmousedown="test()"/>
<br/>
<br/>
</apex:form>

<script>

function test() {

alert('in test function');
}

</script>

</apex:page>

 

 

Just to clarify, I don't get the alert box popping up, the page just refreshes.

 

Any ideas?

 

TIA,

 

Marco

 

Message Edited by mt0859 on 05-27-2009 10:03 AM
Message Edited by mt0859 on 05-27-2009 10:04 AM
TehNrdTehNrd

Try this but you may be better off using a regular html button to call this type of javascript method:

 

 

onclick="test();"/>

 

 

 

SuvraSuvra

Hi.. I am also facing similar kind of problem in my code..even "onclick" event also not working..

 

any idea???

kminevkminev
Anyone found a workaround or cause of this issue? I am having the some problem!
SoozeeSoozee

me too!

Starz26Starz26

Soozee wrote:

me too!


use onclick="test(); return false;"

 

also see my thread if your issue include param and class variables:

 

http://boards.developerforce.com/t5/Visualforce-Development/How-to-pass-Paramater-using-CommandButton-A-Tutorial-Lessons/m-p/424215

Starz26Starz26

FYI: This works just fine. (Without the return false; after the alert, the page refreshes)

 

<apex:commandButton value="Alert Me" onclick="test(); return false;" />
<script>
function test(){
   alert('Got it');
}
</script>