You need to sign in to do that
Don't have an account?
How to swap two values in visualforce page
Hi there,
In this visualforce page there are two inputs and one button name as swap. How the swap the values in given two inputs from input-1 to input-2. Please provide suggestions
I tried the above code
VF code:-
In this visualforce page there are two inputs and one button name as swap. How the swap the values in given two inputs from input-1 to input-2. Please provide suggestions
I tried the above code
VF code:-
<apex:page controller="Swap_Values"> <apex:form > <apex:outputLabel >Enter Value</apex:outputLabel> <apex:inputText value="{!x}"/> <apex:inputText value="{!y}"/> <apex:commandButton value="Swap" action="{!SV}"/> </apex:form> </apex:page>Apex code:-
public class Swap_Values { public String y { get; set; } public String x { get; set; } public PageReference SV() { x=y; y=x; return null; } }
try below code,
public class swapex {
public string x {set;get;}
public string y {set;get;}
public pageReference sv(){
string tmp=x;
x=y;
y=tmp;
return null;
}
}
vf:
<apex:page controller="swapex" >
<apex:form >
<apex:outputLabel >Enter Value</apex:outputLabel>
<apex:inputText value="{!x}"/>
<apex:inputText value="{!y}"/>
<apex:commandButton value="Swap" action="{!sv}"/>
</apex:form>
</apex:page>
All Answers
try below code,
public class swapex {
public string x {set;get;}
public string y {set;get;}
public pageReference sv(){
string tmp=x;
x=y;
y=tmp;
return null;
}
}
vf:
<apex:page controller="swapex" >
<apex:form >
<apex:outputLabel >Enter Value</apex:outputLabel>
<apex:inputText value="{!x}"/>
<apex:inputText value="{!y}"/>
<apex:commandButton value="Swap" action="{!sv}"/>
</apex:form>
</apex:page>