+ Start a Discussion
Amit_TrivediAmit_Trivedi 

How to add and remove inputTextArea on button click in repeat tag ?

User-added image
In the above image i would like to add 3rd, 4th and so on upto 10 option on click of add option and implement reove link to remove perticular option(textarea) and if question type is descriptive i would like to hide all options
Best Answer chosen by Amit_Trivedi
Vishnu VaishnavVishnu Vaishnav
Hi,

here is code..
public class TEST{
    public list<String> lstOptions{get;set;}
    public List<Integer> iter {get;set;}
    public string que{get;set;}
    integer i;
    public TEST(){
        lstOptions = new list<String>(); 
        iter = new List<Integer>();
        i=0;
    }
    
    public void addRow(){
        lstOptions.add('');
        iter.add(i);
        i++;
    }
    
    
    //Call this methos on change of select list
    public void hideOptions(){
        lstOptions.clear();
    }
}

=======
<apex:page controller="TEST">
    <apex:form id="frm">
        <apex:inputText value="{!que}"/>
        <table>
     
        <apex:repeat value="{!iter}" var="it">
        <tr><td>
            <apex:inputText value="{!lstOptions[it]}"/>
        </td></tr>
        </apex:repeat>
        </table>
        <apex:commandButton value="Add" action="{!addRow}" reRender="frm"/>

    </apex:form>
</apex:page>

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....

All Answers

Dushyant SonwarDushyant Sonwar
you can use wrapper class to acheive this type of result.
public class option{
public string id{get;set;}
public <Type Of Object Binded On Page> name of Object{get;set;}
}
 call that function passing that id...
 
dev_sfdc1dev_sfdc1
Hi Amit,
You can try using jquery/ javascript refer links below:

http://www.mkyong.com/jquery/how-to-add-remove-textbox-dynamically-with-jquery/
http://www.smarttutorials.net/dynamically-add-and-remove-textbox-using-jquery/


 
Vishnu VaishnavVishnu Vaishnav
Hi,

here is code..
public class TEST{
    public list<String> lstOptions{get;set;}
    public List<Integer> iter {get;set;}
    public string que{get;set;}
    integer i;
    public TEST(){
        lstOptions = new list<String>(); 
        iter = new List<Integer>();
        i=0;
    }
    
    public void addRow(){
        lstOptions.add('');
        iter.add(i);
        i++;
    }
    
    
    //Call this methos on change of select list
    public void hideOptions(){
        lstOptions.clear();
    }
}

=======
<apex:page controller="TEST">
    <apex:form id="frm">
        <apex:inputText value="{!que}"/>
        <table>
     
        <apex:repeat value="{!iter}" var="it">
        <tr><td>
            <apex:inputText value="{!lstOptions[it]}"/>
        </td></tr>
        </apex:repeat>
        </table>
        <apex:commandButton value="Add" action="{!addRow}" reRender="frm"/>

    </apex:form>
</apex:page>

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
This was selected as the best answer
Amit_TrivediAmit_Trivedi
Thanks for the help.