beny lim
beny lim

Reputation: 1304

Comparing php value and javascript value for checkbox

I have a template consisting of a checkbox and a value retrieve from php. How can I compare the php value with the value of {{filename}}? It the two value matched, then set the checkbox to checked.

<script type="text/template" id="imageTemplate">
    <div class="row gc_photo" id="gc_photo_{{id}}" style=" border-bottom:1px solid #ddd; padding-bottom:20px; margin-bottom:20px;">
                    <div class="checkbox">
                        <label>
                            <input onclick="return set_parentimage(this);" type="radio" name="primary_image" id="{{id}}_{{filename}}" value="{{id}}" {{#primary}}checked="checked"{{/primary}}/> <?php echo lang('main_image');?>
                        </label>
                    </div>
    </div>
</script>

Upvotes: 3

Views: 84

Answers (1)

biozid bostami
biozid bostami

Reputation: 664

Try using this i came across earlier ...... It was suggested to me. My problem was kind similar to yours. Here i send a value from PHP to javascript. Hope it will help you.

<?php
//somewhere set a value
 $var = "a value";
?>

 <script>
// then echo it into the js/html stream
// and assign to a js variable
spge = '<?php echo $var ;?>';

// then
alert(spge);

</script>

Upvotes: 1

Related Questions