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

Question Related to Overriding Visual Force Page with a Button?

There is a Custom Object named Quotation.There is a look up field in  a Quotataion which is related to Items..


My Requirement is :I need to add multiple items in the Quotation.I created a Button field next to the lookup field in the Quotation which relates to Item.When that Button is Clicked A new look up field should be created automatically



My Code:

<apex:page standardController="Quotation__c">
<script language="javascript">
function fun()
<!-- var btnCopy = document.getElementById("{!$Component.btncopy}"); -->
document.getElementById(btncopy).appendChild('<apex:form><apex:inputfield value="{!Quotation__c.Item__c}"/></apex:form>') ;
<apex:inputField id="btncopy" value="{!Quotation__c.Item__c}"/>
<apex:commandButton  value="Add" onclick="fun()"/>


But In this code when the Button is Clicked no action is taking place..Please Provide a Solution


You need to rethink what you're trying to do.  Ask yourself these questions:


1. Even if I did manage to get another <apex:inputField> to show up on the page, where would the value I enter there be stored.  There's only one Item__c lookup field on the Quotation object.   If you need many then you should look into Many to many junction objects.


2. Visual Force is a pre-processed language.  Salesforce takes your VF page code and uses it to generate HTML/Javascript which it sends to your browser.  So, while you certainly can do Dom manipulation to insert new HTML elements into your page, you can't input more <Apex> tags because the preprocessing has already been done.


So, you need to do this differently.  Answer question 1 and number 2 should be easier.



Best, Steve.


Thanks for the Response.Can u suggest me a solution how to proceed to the Requirement...After all the object is overridden by the visual force page





instead of doing this in Javascript, the correct way would be do call a controller method that would add a new "Quotation" object to a List and you can iterate over the List in your visual force page.


Check for an example of how to do this.