Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The echoed php value from $bt1 (ID=inputdata3) doesn't work correctly in the javascript.

The hardcoded value from id=inputdata2 works fine.

What do I need to do to get the softcoded php value to work correctly?

..ultimately use the function to generate a barcode.

Thanks

What I have tried:

<div id="externalbox" style="width:4in">
    <div id="inputdata2">78910</div>
</div>

<div id="externalbox" style="width:4in">
    <div id="inputdata2">78910</div>
</div>

<div id="externalbox" style="width:4in">
    <div id="inputdata3"><?php echo $bt1;?>  </div>
</div>

<script type="text/javascript">
    // $(document).ready(function() {
        function get_object(id) {
            var object = null;
            if (document.layers) {
                object = document.layers[id];
            } else if (document.all) {
                object = document.all[id];
            } else if (document.getElementById) {
                object = document.getElementById(id);
            }
            return object;
        }
        get_object("inputdata").innerHTML = DrawCode39Barcode(get_object("inputdata").innerHTML, 1);
        get_object("inputdata2").innerHTML = DrawCode39Barcode(get_object("inputdata2").innerHTML, 1);
        get_object("inputdata3").innerHTML = DrawCode39Barcode(get_object("inputdata3").innerHTML, 1);
</script>
Posted
Updated 30-Jul-22 21:12pm
Comments
Richard MacCutchan 17-Dec-21 4:16am    
I just tried that and it works correctly. I can only assume that $bt1 is not defined. Check the browser console to see if any errors are showing.

1 solution

to integrate a var in html/js from PHP :


<?php global $bt1 = '........'; ?>
// the keyword 'global' make the var for all scopes in all php pattern.
// few html tags

<?php echo($bt1); ?>

//
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900