+ Start a Discussion
Aki99Aki99 

Use image in place of checkbox in visualforce

Hi,

I want to use images in place of default checkbox in salesforce. So that when the user clicks on the image its corresponding checkbox gets selected at the back end.Any idea how can I achieve that in visualforce??

 

Thanks in advance

 

Regards,

Aakash

Best Answer chosen by Aki99
jiah.choudharyjiah.choudhary
@Aki99,

Oh Okay. Use 2 images having rendered attribute. On click of first image, perform operations such that at back end your checkbox is being updated. and then rerender that block. which will display your other image. For rendered, you can use checkbox value.

just a rough idea :

1. <apex:image id="idImage1" rendered="{!IF(CheckboxValue,true,false)}" onclick="callAF()">
<apex:image id="idImage2" rendered="{!IF(CheckboxValue,false,true)}" onClick="callAF()">

2. In action Function, call a method in controller, that updates the checbox value.

3. Rerender the image block in actionFunction.

All Answers

jiah.choudharyjiah.choudhary

@Aki99,

 

You can make use of standard images, as in :

 

<img src="/img/checkbox_unchecked.gif"/>
<img src="/img/checkbox_checked.gif"/>

Aki99Aki99

Thanks Jiah for such a prompt reply.

But I guess I wasn't able to clarify my problem. What I want is my user only sees image in place of checkboxes and when he/she clicks on the image, its corresponding checkbox is selected and the color or source of the image is also change to show the select. Also in case of a select click the image and thus the checkbox is unselected from the list. Just as we do in case of check boxes, I need that same functionality but using custom mage in place of checkbox.

 

 

jiah.choudharyjiah.choudhary
@Aki99,

Oh Okay. Use 2 images having rendered attribute. On click of first image, perform operations such that at back end your checkbox is being updated. and then rerender that block. which will display your other image. For rendered, you can use checkbox value.

just a rough idea :

1. <apex:image id="idImage1" rendered="{!IF(CheckboxValue,true,false)}" onclick="callAF()">
<apex:image id="idImage2" rendered="{!IF(CheckboxValue,false,true)}" onClick="callAF()">

2. In action Function, call a method in controller, that updates the checbox value.

3. Rerender the image block in actionFunction.
This was selected as the best answer
aswanijagadesh1.397398535585991E12aswanijagadesh1.397398535585991E12
i want entire code will u try now please