0

i try to get the value from <input type="checkbox">and pass it to my variable on controller but i always get 'Argument cannot be null'. i already try using inputHidden to <select> tag and <input type="text"> and it works but why it didn't work on <input type="checkbox">.

Did i do it correctly ? i do it based on Get text input value with the help of HTML and pass it to controller answer

--Visualforce--

<apex:inputHidden value="{!CC}" id="ccId"/> 
<label><input type="checkbox" onchange="document.getElementById('{!$Component.ccId}').value = this.value;" />Kartu Kredit</label> 

--Apex Class--

public Boolean CC{get;set;}
public PageReference Submit(){
   web2lead.Credit_Card__c =CC;
   update web2lead;
}
1

Use this.checked instead this.value

We know in case of checked box, we need to check checked attribute not value.

if it a input type="text" then we need to use value

<apex:inputHidden value="{!CC}" id="ccId"/> 
<label><input type="checkbox" onchange="document.getElementById('{!$Component.ccId}').value = this.checked;" />Kartu Kredit</label>

Class

public Boolean CC{get;set;}
public PageReference Submit(){
   web2lead.Credit_Card__c =CC;
   update web2lead;
}
0

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.