0

I have to pass HTML input text value to apex controller. I am working, when checkbox is checked it value passes to the input text. Like, when a field of type checkbox 'Apple' is checked Apple pass to the html text field. This value(Apple) i need to pass in apex Controller. I can not use apex:inputtext, because i am not getting value in this. I have to use input type="text".Below is my code Please help!

 <script type="text/javascript">
function copyMe(checkbox) {
    if(checkbox.checked){
    //alert('####' +txt);
        var textVal = document.getElementById('txt').value;
        var newVal;
        if(textVal == ''){
            newVal = checkbox.value;
        } else {
            newVal = textVal + ', ' + checkbox.value;
        } 
        document.getElementById('txt').value = newVal;
    }
} 
</script>
<input type="checkbox" class="chb" value="Apple" onClick="copyMe(this);"/>Apple 
<input type="text" value="{!Description}" id="txt"/> 
0

1 Answer 1

1

You can take help of action function here. In the param pass this value as a parameter

<apex:outputLink value="javascript:if (window.confirm('Are you sure?')) DeleteQuoteLineItem('TEST VALUE');">
    Del
</apex:outputLink>

    <apex:actionFunction action="{!DeleteQuoteLineItem}" name="DeleteQuoteLineItem" reRender="content">
        <apex:param name="myParam" value=""/>
    </apex:actionFunction>

Controller:

public void DeleteQuoteLineItem(){

    //either of the next 2 lines will work, 
    string passedParam1 = Apexpages.currentPage().getParameters().get('myParam');
    string passedParam2 = system.CurrentPageReference().getParameters().get('myParam');
    system.debug(passedParam1);
    system.debug(passedParam2); // now use this as you want
}

There is a good blog about this where you can read it in detail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .