+ Start a Discussion
SalesforceLearnerSalesforceLearner 

Java script to update the input field of an object on VF page

I created a VF page with input fields of Account Object. I created a select list on Vf page using controller. I want to update the input field(selected__c : datatype--text) with same value selected option in select list.

I tried below code but it is not working as i am making mistake somewhere.
Can anyone help me with this .
 
<apex:pageblocksection>

<apex:selectList value="{!selectedVal}" multiselect="false" readonly="true"  onchange="updateField()" size="1" id="ddlViewBy">
<apex:selectOptions id="selectid" value="{!contact}"/>
</apex:selectList>
<apex:inputfield id="customfield" value="{!Account.Match__c}"></apex:inputfield>
       
 </apex:pageblocksection>
<script>
 function updateField() {
 var e = document.getElementById("ddlViewBy");
 var strUser = e.options[e.selectedIndex].value;
 document.getElementById("customfield") = strUser;
  
 }

 </script>
Controller :
 
public List<SelectOption> getcontact() {   
    List<SelectOption> options = new List<SelectOption>();
     Account a = [Select id,Name,OwnerId,Match__C FROM Account where id =: this.account.id]; 
   con  = [Select id, Name from Contact  where OwnerId =: a.OwnerId];
    if (con.Size() >0)
 {     
    for(Contact c : con){
    if (c.Name != null)
      options.add(new SelectOption(c.Name,c.Name));
     }
   }
   return options;
}