1

I want to code this view of CI, How do I write the js and call it in CI? Here is the code:

<script type="text/javascript" src="<?php base_url() ?>/assets/js/jquery.js"></script>
    <script type="text/javascript" src="<?php base_url() ?>/assets/js/qrcodelib.js"></script>
    <script type="text/javascript" src="<?php base_url() ?>/assets/js/webcodecamjquery.js"></script>

    <script type="text/javascript">
        var arg = {
            resultFunction: function(result) {
                $('#as').append($("<input hidden='text' name='code' id='road' value='" + result.code + "'><br><label>QR Code Berhasil Discan, Silahkan Klik Allow / Berbagi data lokasi</label><br>"));
                var x = document.getElementById("ar");
                if (navigator.geolocation) {
                    navigator.geolocation.watchPosition(showPosition);
                  } else { 
                    x.innerHTML = "Geolocation is not supported by this browser.";
                  }
                  function showPosition(position) {
                    x.innerHTML="<input hidden='text' name='lat' value='" + position.coords.latitude + 
                    "'><input hidden='text' name='long' value='" + position.coords.longitude + "'><label>Lokasi Telah didapatkan, silahkan Klik Submit</label>";
                }
            }
        };
        $("canvas").WebCodeCamJQuery(arg).data().plugin_WebCodeCamJQuery.play();            
    </script>

1 Answer 1

1

you can create a custom js file, add your js code in to that file. and include new js file in your CI view.

 <script type="text/javascript" src="<?php base_url() ?>/assets/js/jquery.js"></script>
 <script type="text/javascript" src="<?php base_url() ?>/assets/js/qrcodelib.js"></script>
 <script type="text/javascript" src="<?php base_url() ?>/assets/js/webcodecamjquery.js"></script>
 <script type="text/javascript" src="<?php base_url() ?>/assets/js/custJs.js"></script>

Take new file and name is as custJs.js, and add below code in custJs.js file

  var arg = {
        resultFunction: function(result) {
            $('#as').append($("<input hidden='text' name='code' id='road' value='" + result.code + "'><br><label>QR Code Berhasil Discan, Silahkan Klik Allow / Berbagi data lokasi</label><br>"));
            var x = document.getElementById("ar");
            if (navigator.geolocation) {
                navigator.geolocation.watchPosition(showPosition);
              } else { 
                x.innerHTML = "Geolocation is not supported by this browser.";
              }
              function showPosition(position) {
                x.innerHTML="<input hidden='text' name='lat' value='" + position.coords.latitude + 
                "'><input hidden='text' name='long' value='" + position.coords.longitude + "'><label>Lokasi Telah didapatkan, silahkan Klik Submit</label>";
            }
        }
    };
    $("canvas").WebCodeCamJQuery(arg).data().plugin_WebCodeCamJQuery.play(); 
Sign up to request clarification or add additional context in comments.

3 Comments

Its Work, Thanks Pals
@BiBearProgram On Stack Exchange sites the way to say thank you is to upvote helpful answers and accept the most helpful by clicking the tick mark on the left. You're free to switch later when a better answer comes along.
Ok, Done. Sorry i newbie here :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.