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
anukarthi_nimmalaanukarthi_nimmala 

Pass Html input text value to apex controller

Hi,

 

Please someone tell me how to pass html input text value to my apex controller.PLease  give me an example of doing so if possible .

 

 

                                                                                                                                                                                  Thanks and regards

                                                                                                                                                                                                Anu...

 

RAJU_DEEPRAJU_DEEP

Hello Anu,

                   I also stuck on this kind issue, so I think you should try little bit of javascript in your code. Just look at the example:

 

 

Visual Force Page Code:
<apex:page controller="TestFieldPopulationController" id="pg">
    <script type="text/javascript">
        function userInput(){
            var UInput=document.getElementById("{!$Component.pg.frm.in}").value;
            return UInput;
        }
        
    </script>
    
    <apex:form id="frm">
        <apex:actionFunction name="hitMe" action="{!iWantMyJSValues}" rerender="jsvalues">
            <apex:param name="one" value="" />
            <apex:param name="two" value="" />
            <apex:param name="three" value="" />
        </apex:actionFunction>
        
        <apex:outputPanel id="jsvalues">
            <apex:panelGrid columns="2">
                Value One:<apex:inputText id="in" value="{!valueOne}" onclick="hitMe(userInput(),'{!email}','{!state}' )"/>
                Value Two:<apex:inputText value="{!valueTwo}" />   
                Value Three:<apex:inputText value="{!valueThree}" />
            </apex:panelGrid>        
        </apex:outputPanel>
   </apex:form>
</apex:page>


Controller Code:

public class TestFieldPopulationController 
{
    public String valueOne { get; set; }
    public String valueTwo { get; set; }
    public String valueThree { get; set;}
    public String email{ get; set;}
    public String state{ get; set;}
    
    public PageReference iWantMyJSValues() 
    {
        valueOne = Apexpages.currentPage().getParameters().get('one');
        valueTwo = Apexpages.currentPage().getParameters().get('two');
        valueThree = Apexpages.currentPage().getParameters().get('three');
        email = [select Email__c from Employee_Detail__c where name =:valueOne].Email__c;
        state = [select State__c from Employee_Detail__c where name =:valueOne].State__c;
        return null;
    }
}


 

 

In the above example Custom object(Employee_Detail__c) is used. The value inserted by the user is saved in these three variables and these variables can be used any where in the controller.

Hope this helps you? If so, please mark it solved.

 

Regards

Raju.

 

 

anukarthi_nimmalaanukarthi_nimmala

HI Raju,

 

Thanks alot for your reply, But in my scenario i want to pass the Uinput   variable to apex controller.When iam trying to work with this example i could only pass inputtext values which ever u put in panel grid but i want to pass the variable in jscript function to apex controller.So please tell  me how to do that.

RAJU_DEEPRAJU_DEEP

As you see in the previous example the variable valueTwo can be used anywhere in the controller.

 

 

<apex:page controller="AccSave">
<apex:form>
Account Name : <apex:inputText value="{!aName}"/>
<apex:commandButton action="{!save}" value="Save"/>
</apex:form>
</apex:page>


public class AccSave {
public String aName{get; set;}

public void save(){
Account a = new Account(
Name = aName
);
insert a;
}
}

 

In this code the  value of inputText is passed through variable from vf to controller.

 

 

Hope this helps you? If so, please mark it solved.

Regards

Raju.

 

 

krishnagkrishnag

 hi anu,

 

what do u want to do getting the input values from page .do u want to save it in some object?or u want to pass it to another page? 

anukarthi_nimmalaanukarthi_nimmala

Hi Krishna ,

 

Thanks for your support .Yes you are right i want to save the input values in to some customobject  and that input value is html input value but not apex:input value.So please mtell me how could i do this.

 

                                                                                                                                                                   Thanks and regards,

 

                                                                                                                                                                                    Anu.....

anukarthi_nimmalaanukarthi_nimmala

Hi,

Thanks for your reply, But i want to pass avalue from the html input tag. I mean to say i have an html input value in visualforce page now i want to pass that html input terxt value to controller as if u passing the apex:input value in the example given .So please help me how could i achieve this.

 

                                                                                                                             Thanks and regards,

                                                                                                                                                  anu...