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

Issue setting a hidden input field with Javascript


I am trying to implement some basic inline editing functionality on a Visualforce page with some custom Javascript code. I have the table setup so that when a user clicks a specific row the row elements turn into text input areas. What I've tried to do is when the user clicks the update button, the Javascript code sets two inputHidden elements to the newly edited text and then posts the apex:form element containing these two inputHidden elements. I have run into two issues here:

1. The page isn't recognizing my {!$Component.elementID} elements for the two inputHidden fields, but it is for the form element; I've got around this by adding in the full ID manually. Not sure why it works for some elements and not the others
2. When the form gets submitted (which it seems like it does successfully submit), my setDescription method runs, but doesn't update the description for the corresponding Account. I've put in some System.debug code in the setDescription method and it does show the new value I had entered in the form. The Apex log does turn up this error: "thePage:form:aDescription: An error occurred when processing your submitted information." However, it also states the select and update statements ran sucessfully.

Any help here is appreciated. And, if there is a better way to do this I'd be interested. Here is my page:

<apex:page controller="revAController" id="thePage">

   font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
   font-size: 12px;
   background: #fff;
   width: 50%;
   border-collapse: collapse;
   text-align: left;
  #hor-minimalist-b th
   font-size: 14px;
   font-weight: normal;
   color: #666666;
   padding: 10px 8px;
   border-bottom: 2px solid #666666;
  #hor-minimalist-b td
   border-bottom: 1px solid #ccc;
   color: #666666;
   padding: 6px 8px;
  #hor-minimalist-b tbody tr:hover td
   color: #666666;
   background: #FAF8CC;
  <script type="text/javascript">
   var data = new Array();
   function Item(row){
    this.Row = row;
    this.Name = row.cells[0].innerHTML;
    this.Dsc = row.cells[1].innerHTML;
    this.Owner = row.cells[2].innerHTML;
    var _this = this;
    var mode = "view";
    row.onclick = function() {
     if (mode != "edit") {
     mode = "edit"
     return false;

    this.Edit = function() {
     this.NameField = document.createElement("input");
     this.NameField.type = "text";
     this.NameField.value = this.Name;
     this.Row.cells[0].innerHTML =  "";
     this.DscField = document.createElement("input");
     this.DscField.type = "text";
     this.DscField.value = this.Dsc;
     this.Row.cells[1].innerHTML =  "";
     this.UpdateLink = document.createElement("a");
     this.UpdateLink.innerHTML = "update";
     this.UpdateLink.href = "#";
     this.UpdateLink.onclick = function() {
    this.Update = function() {
     var form = document.getElementById("{!$Component.form}");
     document.getElementById("thePage:form:aName").value = this.Name;
     document.getElementById("thePage:form:aDescription").value = this.DscField.value;
     //aName.value = this.Name;
     //aDescription.value = this.DscField.value;
   window.onload = function() {
    var table = document.getElementById("hor-minimalist-b");
    for(var i=1; i<table.rows.length; i++){
     data.push(new Item(table.rows[i]));

 <table id="hor-minimalist-b">
          <th scope="col">Account Name</th>
          <th scope="col">Account Description</th>
             <th scope="col">Owner</th>
  <apex:repeat value="{!accounts}" var="account" id="theTable">
     <apex:outputText value="{!}"/>
     <apex:outputText value="{!account.description}"/>
     <apex:outputText value="{!account.owner}"/>
 <apex:form id="form">
  <apex:inputHidden id="aName" value="{!Name}"  />
  <apex:inputHidden id="aDescription" value="{!Description}"  />

 And, here is my controller:

public class revAController {
 List<Account> accounts;
 public List<Account> getAccounts() {
  accounts = [select name, description, from account limit 10];
  return accounts;
 Account acct = new Account();
 public String getName() { return; }
 public void setName(String aName) { = aName; 
 public String getDescription() { return acct.Description; }
 public void setDescription(String aDescription) {
  System.debug('setDescription working'); 
  Account a = new Account();
  a = [select id, name, description from account where name = : acct.Name limit 1];
  a.description = aDescription;
  update a;



-- Matt