You need to sign in to do that
Don't have an account?
Click apex:commandButton using javascript
Hi all,
I have a small requiremnet where i need to click a apex:commandbutton using javascript because it perform one action. which should be only done by javascript on load
i have tried in html it is working fine but not working in salesforce
<button id="d">Button #1</button>
document.getElementById("d").click();
i have tried in salesforce like this but it is not working
<apex:commandButton id="cmdUpload11" action="{!page2onLoad}" value="cccc"/>
window.onload=function onclickdemo()
{
document.getElementById('cmdUpload11').click();
}
Please Help me to solve this issue its urgent
Hello,
Why aren't you using the action attribute of the apex:page? http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_page.htm
From your use case it's exactly what you need...
Ty,
Adrian
Thanks Adrian
actually my reqiurement is on onchange() it should be called in that i want to click a apex:commandButton which has an action . it should not be given direct like
<apex:actionFunction action="{!page2onLoad}"/>
or
<apex:page action="{!page2onLoad}"/>
because it perform action when ever page is loaded which i dont want
WHy dont you use actionfunction to fire the same event ?
and why you want to invoke click even of the button ?
I have to call same function in controller 2 time
1. for creating id
2. to update values in id
it will working fine when i using <apex:page action="{!function}"> and action funtion for second time
and if i give two action funtions with same function name it is not working.
but the problem is apex:page is calling the function whenever the page is loaded (it is creates id's eventhough we refresh the page ) which i dont want
so when i clikck a button which as action in it for id creating and action funtion to update values in id it is working fine
so i need to call the button( click() ) using javascript so that it will work
But seems like you are not doing in a proper way.
Why you need explicit two calls ?
Why arent you merging them into one?
Create Id and Update Id in same action ?
controller
pageload()
{
id ids;
if(ids==null)
{
insert ids;
}
else
{
update ids;
}
page
if i do like this
1.<apex:page action="{!pageload}">//to create id
2.<apex:actionFunction action="{!pageload}"/>// to update id
3. </apex:page>
it is working fine but the action in line 1 calls every time when the page is loaded which i dont want unwanted number of ids are created
----------------------------------------
i want somthing like this
controller
same as above
page
<input type="file" onchange="testing();"/>
.<apex:actionFunction name="pageload" action="{!pageload}"/>
<script>
function testing()
{
page(); // line A //create id
.......
.......
......
after some work again i have to call same function to update
page(); // line B // update id with some value in it
}
function page() {
pageload();
}
</script>
at line A it is creating id in controller but not returing back to page
----------------------------------------------------------
so i am trying something like this
<input type="file" onchange="testing();"/>
.<apex:actionFunction name="pageload" action="{!pageload}"/>
<apex:commandbutton action=""{!pageload}" id="b1"/>
<script>
function testing()
{
document.getElementByid('b1').click(); // line C it goes and creates id and comes back from controller
.......
.......
......
after some work again i have to call same function to update
page(); // line D // updating id using some values
}
it is working fine while clicking the button and after onchange() works but i dnt want the button to be clicked manually it should be called starting of onchange() so the it can create id and comes back to page