0

Is it possible for me to reload a div when a checkbox in the same document is clicked?

<html:checkbox property="checkbox" styleId="checkbox">
<div id="divToBeRefreshed">
    //content
</div>

I'd rather do it using pure javascript but ajax is ok too if there isn't another solution.

3 Answers 3

1

Well the answer by @karthick is for change event it will reload the content if the checkbox is unchecked also you can use the below code

$('#checkbox').change(function(){

    if($(this).is(':checked')){
        // Checkbox is checked.
        $("#divToBeRefreshed").html('your content');
    }else{
        // Checkbox is not checked.
    }   

});

make your id of checkbox is set to

id='checkbox'

Hope this help you

Sign up to request clarification or add additional context in comments.

Comments

0

try this

 $("#checkbox").on('change',function(){
       $("#divToBeRefreshed").html('your content');
 });

Comments

0

The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea> boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse.Hope this is what u meant mate

HTML

<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car 
<div id="divToBeRefreshed">

</div>

JS

$("input[name=vehicle]").on('change',function(){
      $("#divToBeRefreshed").html($(this).val());
 });

if you want to fire an event when a checkbox is checked / unchecked: use the below code too.

if( $(this).is(':checked') )

Fiddle

http://jsfiddle.net/BzgrW/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.