Wednesday, August 19, 2009

Jquery--- checkbox check on/off display/hide some fields

I have one checkbox, I want to check on this checkbox display some textbox and lable, off check hide these textbox and lables, here is the function to do it:

$("#ckIsAgent").click(function() {
SwitchShowAgent();
});


function SwitchShowAgent() {
var ckValue = $("#ckIsAgent:checked").val();
if (ckValue)
ShowAgentData();
else
HideAgentData();
}
function HideAgentData() {

$("#lblAgentName").hide();
$("#txtAgentName").hide();
$("#lblAddress").hide();
$("#txtAddress").hide();
$("#lblSiteLink").hide();
$("#txtSiteLink").hide();
}
function ShowAgentData() {
$("#lblAgentName").show();
$("#txtAgentName").show();
$("#lblAddress").show();
$("#txtAddress").show();
$("#lblSiteLink").show();
$("#txtSiteLink").show();
}


the key part is using var ckValue = $("#ckIsAgent:checked").val(); to check the checked/not checked value

No comments: