+ Start a Discussion
ministe2003ministe2003 

Javascript breaks my code

Hello,

 

I have a visualforce page which I am passing data from into apex code and using input from the page to update an object.

 

In this example I have a table of data, each ending with a checkbox and a text field.  the text field is disabled until the user ticks the checkbox.  at that point, I use javascript to enable the text field.

When the user is done they click a submit button which calls apex code.

 

This all works fine when I dont have the javascript involved.  ie if the text box is always enabled, the data is passed and object updated fine, however when I do try and involve the javascript to enable/disable the text field as the checkbox is toggled, no data seems to be being passed from the text field and the object is not getting updated.  well, it is, just not that text field.

 

Does anyone have any ideas why this would be happening and if it cannot be fixed, is there another way to link the textfield to the checkbox?

 

Thanks

 

Steven

OnDem DevOnDem Dev
Can you please post the javascript code?
ministe2003ministe2003

actually now I've done more testing, it seems it works with the javascript, it is the fact that the text box is disabled on page load that is the problem.  I want them disabled by default and only enabled when the checkbox is ticked.  Why would having them disabled by default cause an issue?

 

Steven

ministe2003ministe2003

I've tried rerendering with actionsupport instead but im having no luck.  the boxes are initially not rendered since the checkboxes are not ticked, but when I do tick them, no text boxes reload :(

I've gone as far as to tell it to rerender the entire page (id OW_EditSubmission) but that doesnt seem to do anything

 

                <apex:column headerValue="Edit?">
                    <apex:inputcheckbox id="tick" selected="false">
                        <apex:actionSupport event="onclick" rerender="OW_EditSubmission"/>
                    </apex:inputcheckbox>
                </apex:column>
                <apex:column headerValue="Change Required" id="comcol"> <apex:inputText maxLength="255"  rendered="{!$Component.table.tick.selected == 'true'}" id="comment" value="{!li.Edit_Reason__c}" /></apex:column>

craigmhcraigmh

Yeah, this is still an issue. I even have the proper JavaScript code to set the disabled attribute to either "" or "disabled" instead of "true" or "false", but the value of the SelectList isn't being returned.

craigmhcraigmh

Figured out a solution. I have an apex:actionSupport element in the apex:inputCheckbox element, and re-render only the disabled control.

 

<apex:inputCheckbox value="{!isEnabled}">
   <apex:actionSupport event="onclick" action="{!chkChanged}" rerender="txt" />
</apex:inputCheckbox>
<apex:inputText id="txt" disabled="{!!isEnabled}" value="{!txtValue}" />