Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 985
beny lim Avatar asked May 09 '26 03:05

beny lim


1 Answers

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>
like image 139
biozid bostami Avatar answered May 11 '26 17:05

biozid bostami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!