Input is not appearing checked

Asked

Viewed 58 times

0

I have a input of which according to user data in your session it comes marked or not. The problem is that even the input owning checked="checked", he doesn’t come marked.

Code of input together with the div of which he is:

<div class="no-message">
      <input type="radio" id="isgift0" name="isgift" value="0" style="display: none;" class="arredondado" <?php if(Mage::getSingleton('core/session')->getInputMensagem() == 1) echo 'checked="checked"' ?> /> 
      <label for="isgift0"><?php echo $this->__("I do not want to send a message") ?></label>
 </div>

In that label contains a code that CSS that uses an image above the input as if it were the same, but this does not interfere in the functionality.

Codice CSS:

input[type="radio"].arredondado:not(checked) + label:before {
    content: "...";
    display: inline-block;
    margin-top: -2px;
    vertical-align: middle;
    margin-right: 10px;
    background: url(../../images/icons.png) no-repeat -53px -529px;
    width: 22px;
    height: 23px;
    color: transparent;
    border-radius: 0 !important;
    border: none !important;
}

2 answers

1

It is as display None and you can switch to an if ternary getting like this:

<input type="radio" id="isgift0" name="isgift" value="0"
       class="arredondado" <?php echo Mage::getSingleton('core/session')->getInputMensagem() == 1 == 1 ?  'checked="checked"' : ''?> />

css:

 input[type="radio"].arredondado:not(checked) + label:before {
        content: url(icon2.png);
        display: inline-block;
        margin-top: -2px;
        vertical-align: middle;
        margin-right: 10px;
        width: 22px;
        height: 23px;
        border-radius: 0 !important;
        border: none !important;
    }
  • It didn’t work out, no input continues not to come checked... and nor is the issue of display: none, because I have a label containing a before in the CSS with an image referring to input. Inspecting the code and giving a display: block in the input, he doesn’t come checked.

  • Try to edit the question then with more details, then try to help

  • I updated the question with some more information.

  • It’s still a little confusing for me, but I put the image instead of the background in the content and removed the color, I will edit there as I left the class, but I do not know if it is correct, if you want to post all css. to see if there’s nothing about writing.

  • I believe the mistake is not CSS, for even the input coming with the property checked="checked", he doesn’t come checked.

0


I solved this problem by simply doing a check with jQuery, along with php on the page loading, and thus, according to the user’s data in their session, assigning the via the .prop() the property checked to input.

Code of script:

<script>
    $j(document).ready(function () {
    <?php 
       if(Mage::getSingleton('core/session')->getInputMensagem() == 1) {
    ?>
       $j('#isgift0').prop('checked','checked');
    <?php
       }
    ?>
    });
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.