You need to sign in to do that
Don't have an account?

Dynamic input text creation based selected pick list value
Hi Friends
I am new in visual force development .Dynamically how to create input text boxes based on the selected pick list value in visual force page. for ex: If the picklist value is 4 , four text boxes will create in the visual force page. Please any one can guide me to achieve this problem..
Thanks
Sundar
Hi sundar,
Try this code.
Visual force page:
<apex:page controller="dynamictextboxes">
<apex:form >
<apex:selectlist value="{!picklistselectedvalue}" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" action="{!SortTheList}"/>
</apex:selectlist>
<apex:pageBlock>
<apex:pageBlockSection >
<apex:pageblockTable value="{!data}" var="e">
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
</apex:pageblockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Lakshmi
All Answers
You can do this with Wrapper class.
In VF page:
<apex:selectlist //give the value of picklist>
</apex:selectlist>
<apex:repeat value="{!wraplist}" var="w1">
<apex:inputtext value="{!w1.text}"/>
</apex:repeat>
In class
public list<warp> wraplist{set;get;}
public class wrap{
public string text{set;get;}
}
public void sortthelist(){
for(integer i=0;i<picklistselectedvalue;i++)
{
wrap w=new warp();
wraplist.add(w);
}
}
Hi,
Actually i am also need same requirement. i use the code as
Whem i am execute the page it gives the error like as
System.NullPointerException: Attempt to de-reference a null object
Class.dynamictextboxes.sortthelist: line 29, column 1 External entry point
please help me how to solve these..
Thanks,
Lakshmi.
nagalakshmi,
You never initialize your list so you get that error.
Sundar,
I took the code nagalakshmi gave, and modified it to be simpler for you. Nontested of course, so there may be minor bugs but if there are they shouldn't be hard to find.
Hi Sundar,
try this code it is working, which has been send by damien. But there is some little bit modifications is there..
Visual force page:
<apex:page controller="dynamictextboxes">
<apex:form >
<apex:selectlist value="{!picklistselectedvalue}" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" action="{!SortTheList}"/>
</apex:selectlist>
<apex:repeat value="{!wraplist}" var="w1">
<apex:inputtext value="{!w1.name}"/>
</apex:repeat>
</apex:form>
</apex:page>
Thanks,
Lakshmi.
Hi Damien,
Thank you very so much the code is working which you have sent.
Thanks,
Lakshmi
Thanks Damien and Lakshmi
Yes i have tested this code its working fine. Thanks for your support. really its very helpful for me.
Thanks
Sundar
Hi sundar,
Try this code.
Visual force page:
<apex:page controller="dynamictextboxes">
<apex:form >
<apex:selectlist value="{!picklistselectedvalue}" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" action="{!SortTheList}"/>
</apex:selectlist>
<apex:pageBlock>
<apex:pageBlockSection >
<apex:pageblockTable value="{!data}" var="e">
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
<apex:column>
<apex:inputtext value="{!e.name}"/>
</apex:column>
</apex:pageblockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
Lakshmi
nagalakshmi thanks so much for this code. i have project and you saved a tone of time. i took this opportunity to ask you a further question. based to the theory of your code, can you help me achieve the "the sum of these input fields?"
for example if i select 5 from the picklist, i get 1 row with 5 input fields. how to modify my controller (your controller:smileyhappy: ) in order to sum them?
i would really appreciate your response. thank again so much
I have a similar requirement. Here i need to dynamically create input text box based on the picklist value selection. For example, if the picklist value selected is 'Email&Phone', then it should display two input text boxes: one should have input label as "Email" and the other should have "Phone".
Can someone please help me with this?
Thanks in advance.