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
john dsouzajohn dsouza 

pass value of inputText to controller from visualforce page

I have a visual force page purely designed using HTML5.
I have a inputText field called email stored inside a custom object preferences.

If the value in the inputText field changes then I want to capture the changed value into my apex controller for further processing.

Here is what I am trying to achieve.
public class mycontroller {

 public String fanEmail{get;set;}

<apex:page controller="mycontroller docType="html-5.0">
<div class="form-group label-floating">
  <label class="control-label">EMAIL *</label>
   <apex:inputText value="{!Email}" id="memail" 
 <apex:commandButton value="SAVE CHANGES" action="{!btn_profile_saveChanges}" styleClass="btn btn-success"/>

I know that we can use onchange event of <apex:inputText> to achieve this and create a javascript but not sure how to proceed further.

any help will be rewarded.

john dsouzajohn dsouza
since vf page is an HTML based is it possible to use <apex:inputHidden>,
if yes, pls explain.

Malni Chandrasekaran 2Malni Chandrasekaran 2
Please try 
  <apex:inputText value="{!fanEmail}" id="memail"    // input text value should match your controller variable name to bind.

Yes, you can use <apex:inputHidden> to hide any inputtext field.

Please mark it as Solved if it answers your question.
john dsouzajohn dsouza
I am doing something like this

public String C1Email{get;set;}

In the vf page:
 <apex:inputHidden value="{!C1Email}" id="changedemail"/>
     <apex:inputText value="{!C1Email}" id="memail" styleClass="form-control"/>
  <script type="text/javascript">
      var hiddenfield=document.getElementById('{!$Component.PrefForm}').elements['{!$Component.changedemail}'].value;
I am not getting the alert, what I require is whatever email I enter in inputText it should be captured in inputHidden field then from apex controller I will retrieve it.

pls note in vf page , <apex:form id="PrefForm">

please let me know how to proceed further.

Malni Chandrasekaran 2Malni Chandrasekaran 2
Please try
var hiddenfield=document.getElementById('{!$Component.PrefForm.changedemail}').value;

if you have page block or any content tags, please include that Id before input field id (changedemail)

Hope this helps!