How to hide apex:inputField and Javascript?
Is their any way to show/hide my
Option 1: I am able to do this functionality with a <input> tag and javascript but I am unable to save the Stipulation_Reason__c value to a salesforce object.
<input id="textbox2" value="{!stipObj.Stipulation_Reason__c}" />
-------------------------------------------------------------- $(function() { $('#textbox2').on('keyup change', function() { if (this.value.length > 0) { $('#savebutton3').show(); } else { $('#savebutton3').hide(); } }); });Option 2: I am able to save Stipulation_Reason__c to the custom Object but it is not responsive to the javascript
Is it possible to use apex:inputField with JavaScript?
Use of apex:inputField with JavaScript
provides an attribute onchange it binds a JavaScript code to the field onchange event, in this attribute method you can add your JavaScript logic like:
function onStipulationReasonChange(el){ if(el.value.length > 0){ $('#savebutton3').show(); }else{ $('#savebutton3').hide(); } }
You can also add onkeyup if only onchange doesn't work for you.
UPDATE
This works with onkeyup here is the code sample: test.vf
var item = document.getElementById('toggleIt'); function toggleIt(el){ console.log(el.value.length); item.style.display = ((el.value.length > 0)? 'block': 'none'); }
Test.apxc
public class Test { public Contact con{get;set;} public Test(){ con = new Contact(); } public PageReference save(){ insert con; return null; } }