Reputation: 11
I have a RadionButtonList with two values and on click I gotta hide some elements on my page.
I got the following code that triggers on click on a RadionButton. How do I call this on the Page load of my page?
$(document).ready(function () {
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function () {
var clickOrder = $(this).val();
$('#<%= chkColumnList.ClientID %> input').each(function (i) {
var index = ($(this).next('label').text().indexOf(clickOrder));
if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) {
$(this).css('display', 'none');
$(this).next('label').css('display', 'none');
} else {
$(this).css('display', 'inline');
$(this).next('label').css('display', 'inline');
}
});
});
});
Upvotes: 1
Views: 2892
Reputation: 69915
Try this, just call the click
method after you have attached the event handler.
$(document).ready(function () {
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function () {
var clickOrder = $(this).val();
$('#<%= chkColumnList.ClientID %> input').each(function (i) {
var index = ($(this).next('label').text().indexOf(clickOrder));
if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) {
$(this).css('display', 'none');
$(this).next('label').css('display', 'none');
} else {
$(this).css('display', 'inline');
$(this).next('label').css('display', 'inline');
}
});
}).click();
});
Upvotes: 0
Reputation: 263147
You can trigger the click
event right after you've registered your handler:
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input')
.click(function() {
// Your handler...
}).click();
Upvotes: 1
Reputation: 464
$(document).ready(function () {
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click(function () {
var clickOrder = $(this).val();
$('#<%= chkColumnList.ClientID %> input').each(function (i) {
var index = ($(this).next('label').text().indexOf(clickOrder));
if ((index == -1) && ($(this).next('label').text() != 'Cost' && $(this).next('label').text() != 'Clicks' && $(this).next('label').text() != 'Impressions')) {
$(this).css('display', 'none');
$(this).next('label').css('display', 'none');
} else {
$(this).css('display', 'inline');
$(this).next('label').css('display', 'inline');
}
});
}).click();
});
Upvotes: 0
Reputation: 50982
try
$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click();
after your code
Upvotes: 0