Bi Bear Program
Bi Bear Program

Reputation: 13

How to use javascript in CI

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>

Upvotes: 1

Views: 175

Answers (1)

ChandraShekar
ChandraShekar

Reputation: 386

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(); 

Upvotes: 1

Related Questions