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
Rocio VivancoRocio Vivanco 

How to handle two form tags in visualforce page

Hi all,

I am working on this since hours trying many code forms, trying with java script, with ajax, etc., without success.

For a special reason I am using two form tags in my Visualforce code.
I have the same case as here described:

https://salesforce.stackexchange.com/questions/8320/how-to-handle-two-form-tags-in-visualforce-page

My javascript code looks like this (this is one of my trials):
 
<apex:form >
             <script type="text/javascript">
                function grabExName(){
                  var ex = document.getElementById('optypage:cform:new_info').value;
                  alert(ex);
                }
             </script>
             <apex:actionFunction name="UpdateRelevantInformation" action="{!UpdateRelevantInformation}" reRender="out" oncomplete="grabExName();">
                <apex:param name="new_info" value="" />
             </apex:actionFunction>
        </apex:form>
This is in the "<body>" part of the code.

My commandbutton looks like this:
 
<apex:commandlink styleclass="btn btn-primary" id="new_info" value="Save new info" action="{!UpdateRelevantInformation}"  />

When I click that button it should let work the form with id "cform", so that when I click on the button, the functionality behind the action "UpdateRelevantInformation" should work.
Am I missing something here? because when I put the button on the second form, "UpdateRelevantInformation" doesn't do anything, but if I put the button in the first form, where the item Relevant Information should be updated, the button works.

I would appreciate your help.
 
Rakesh Thota 15Rakesh Thota 15
Hi Rocio Vivanco,

please go through this links.​

http://sfdcinpractice.com/index.php/2016/12/08/multiple-one-page/
https://th3silverlining.com/2009/10/19/multiple-forms-in-a-single-visualforce-page/


Hope this helps you.​

Best Regards,
Rakesh Thota.
Rocio VivancoRocio Vivanco
Thanks for the answer. Unfortunately these don't answer my question.
sunny522sunny522
Hi Rocio,
    Since you have 2 forms,the ids may changes.We need to inspect the element and find the exact ids in 2 forms and modify the code as needed using inspect element feature of chrome browser.
For example var ex = document.getElementById('optypage:cform:new_info').value; //This again changes based on where you have kept elements.
 
Rocio VivancoRocio Vivanco
Sunny, thanks for responding. I will check this out. Difficult for me as I am not a Developer but I have to.
Dev-FoxDev-Fox
Hi Rocio,

Unfortunately visualforce can not find required id's in such case. I suggest you to use an action function as a bridge between the forms and then call this action function using button placed within the form to invoke other form actions.

 
Rocio VivancoRocio Vivanco
Thanks Dev-Fox for the suggestion. I will try it.