1

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');
      }
    });
  });
});
1
  • What is a RadionButtonList? jQuery has no such concept. Commented Aug 15, 2011 at 14:39

4 Answers 4

1

You can trigger the click event right after you've registered your handler:

$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input')
    .click(function() {
        // Your handler...
    }).click();
Sign up to request clarification or add additional context in comments.

Comments

0

try

$('#<%= columnsRoundPanel.FindControl("rdlClickOrder").ClientID %> input').click();

after your code

2 Comments

Or just replace the trailing }); }); with }).click(); });.
@TomalakGeret'kal: yes, it's possible, too. Thanks for suggestion!
0
$(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();
});

Comments

0

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();
});

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.