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
jadentjadent 

Programmatically submit Command Button

Is there a way using javascript to programmatically submit a form as if a user clicked on a <apex:commandButton> component?

 

Take the simple vf page

 

<apex:page controller="TestPerms" ><apex:commandButton id="theSectionItem2" value="Search" action="{!testInsert2}" /></apex:page>

 

Is there a way via javascript to submit this form as if they clicked on the submit button? 

 

Best Answer chosen by Admin (Salesforce Developers) 
AmphroAmphro

How about an actionFunction?

VisualForce

 <apex:actionFunction action="{!testInsert2}" name="testInsert">

Javascript

<script>
testInsert();
</script>

All Answers

AmphroAmphro

How about an actionFunction?

VisualForce

 <apex:actionFunction action="{!testInsert2}" name="testInsert">

Javascript

<script>
testInsert();
</script>
This was selected as the best answer
GerhardNewman2GerhardNewman2

Fanastic solution!  Life saver....

 

I needed to find an alternative to <apex:commandbutton> as it would alter the style in my page.

Using an image with an onclick to run the script which calls the actionfunction which submits the form did the trick!

 

Thanks again,

Gerhard