I am setting up value to apex:input using JS as below.

          document.getElementById('{!$Component.street_number}').value = val;
          document.getElementById('{!$Component.street_number}').innerHTML = val;

I see the value being displayed on the page, but when i click submit the value is not being passed to the controller.

Here is the field

           <td class="slimField"><apex:input id="street_number" disabled="true" StyleClass="form-     control" value="{!StreetNumber}"/> </td>
                    <td class="wideField" colspan="2"><apex:input id="route" disabled="true" StyleClass="form-control" value="{!Address}"/></td>

i have these fields defined as public variable in the controller as well.

  public String StreetNumber{get;set;}
public String Address{get;set;}
public String City{get;set;}
  • Setting .value = val should be sufficient there is no need to set the innerHTML. Jul 28 '20 at 6:52

Not sure whether it is the behaviour but when i removed disabled = true from the field, i was able to access the values.

  • This is standard behavior - disabled form controls are not submitted with the form. developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
    – Mark Pond
    Jul 28 '20 at 18:20
  • but using javascript, i am enabling the field and adding value to it before submitting.
    – Rajesh
    Jul 29 '20 at 22:54
  • That isn't demonstrated anywhere in your example code above. That said, any disabled form elements still are not submitted with the form. The presence of the disabled attribute on the element, makes the element disabled. In your javascript, you should be leveraging .removeAttribute('disabled') to completely remove that attribute from the element in the DOM.
    – Mark Pond
    Jul 29 '20 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.