Load page with Jquery event

3

I need some help. There is a jQuery event that works the way I want. When I click, it performs the action.

   $("#SEN").click(function(){
   $("#abre").show(); //ou fadeIn
   });

My intention is that on another page I retrieve data from a client, and when I leave checked on the radio that executes the action, it does not just load the page loading.

Summary is to load the page and execute event of radio selected without user interaction.

I have tried this and it will not:

 $("#SEN").bind('onload, change',function(){
 $("#abre").show();
 });

so also:

 $('#SEN').on('onload, change',function() {
  if (this.checked == true) {
    $("#abre").show();
  } 
});

And with trigger and nothing: (

 $('#SEN').on('onload, change',function() {
  if (this.checked == true) {
    $("#abre").show();
  } 
}).trigger("change");

Maybe you're doing it wrong can you help me?

    
asked by anonymous 23.08.2015 / 17:46

4 answers

0

I was able to do this:

 $('#SEN').on('onload, change',function() {
  if (this.checked == true) {
    $("#abre").show();
  } 
}).trigger("change");
    
25.08.2015 / 20:56
2

Your explanation was a little confusing, but would it be when radio is checked perform an action?

can be done this way:

if ($("#mycheckbox").prop("checked")) {
  alert("Execute uma ação");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><inputtype="radio" name="mycheckbox" id="mycheckbox" checked/>
    
25.08.2015 / 18:15
0

I think the problem with your code is the event you're passing as a parameter.

According to the jquery documentation, when you use the "on" method, the event does not have "on" in the name, for example, if the javascript event is "onload", you should only pass "load" ".

link

In addition, when handling the "change" event, probably checked is another element that will not be "this" because this is a select element and not a checkbox, so you have to get the checkbox by id or some other way.

    
24.08.2015 / 02:36
0

I think you need something like this:

$('.checks')
    .on('load, change',function() {
       var i=0;
     $("input.checks:checked").each(function(){
         i++;
      });

       if ( i > 0) {
           $('#abre').show();
       } else {
           $('#abre').hide();
       }

}).trigger("change");

And the HTML:

<input type="checkbox" class="checks"> Elemento checado 1<br>
<input type="checkbox" class="checks"> Elemento checado 2<br>
<input type="checkbox" class="checks"> Elemento checado 3
<div id="abre" style="display:none">olá!</div>

Here's the example: link

    
27.08.2015 / 19:41