0

JQuery version is 1.3.2

There is a checkbox :

<input type="checkbox" id="flag_concept" name="flag_concept" value="1" />

On document load I want it to be checked :

$(document).ready(function(){
    {/literal}
    { if $oConcept->flag_encours == 1}
    {literal}
    $('#flag_concept').attr('checked','checked');
    {/literal}
    {/if}
    {literal}
});

But it doesnt work !

pheromix
  • 18,213
  • 29
  • 88
  • 158
  • Have you tried `$("#flag_concept")[0].checked = true;` – Satpal Apr 26 '16 at 05:55
  • If using `attr('checked','checked');` doesn't work in your case then some other part of your code is wrong. I'd suggest removing the `if` condition and verifying that it works (it should), and then working out what's wrong with the `if`. I'm unfamiliar with the syntax you're using, so I'm unable to be more help, although I don't see where `$oConcept` is defined. – David Thomas Apr 26 '16 at 06:10
  • it is a Jelix syntax :) – pheromix Apr 26 '16 at 06:15

4 Answers4

1

Try using pure javascript instead of jquery if no problem to do it without jquery:

document.getElementById("flag_concept").checked = true;
<input type="checkbox" id="flag_concept" name="flag_concept" value="1" />

because all suggestions and answers not working for you, i suggest using .trigger() like this :

$( "#flag_concept" ).trigger( "click" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<input type="checkbox" id="flag_concept" name="flag_concept" value="1" />
Shady Alset
  • 5,548
  • 4
  • 21
  • 34
0

You can try ;

$('#encours_concept').attr('checked', true);

And Here is a snippet;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <html>
      <script type="text/javascript">
        $(document).ready(function(){
          $("#chkTest").attr("checked", true);
        });
      </script>
      <body>
        <input type="checkbox" id="chkTest" />
      </body>
    </html>
Vecihi Baltacı
  • 352
  • 4
  • 20
0

You have given wrong id in jquery:

Try by applyinh .prop:

$('#flag_concept').prop('checked', true);
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27
  • `$.prop()` was added in jQuery 1.6. The question specifically asks about an older version. –  Apr 26 '16 at 05:45
  • major issue is id was wrong. otherwise $('#flag_concept').attr('checked','checked'); is working jquery 1.3.2 – Dhara Parmar Apr 26 '16 at 05:52
0

You can use checked property since you need it on page loadright..

<input type="checkbox" id="flag_concept" name="flag_concept" value="1" checked/>