JavaScript Generate Random QR Code OnClick Using qrcode.js generate random code javascript,generate random code python,generate random

I am using qrcode.js for generating qrcode. I want to generate random QR code every time I click into add new tab instead of add new qr code. I created a code for a random number but when I try to add onclick function it add new not to random it.

JSFIDDLE: https://jsfiddle.net/aice09/L8pp9336/
GITHUB: https://github.com/Ailyn09/project102/blob/master/qrcode.html
CODEPEN: https://codepen.io/aice09/pen/Ogqajr

$('#lithird').click(function() {

    var qrcode = new QRCode("qrcode");

    function makeCode() {

        function randomNumber(len) {
            var randomNumber;
            var n = '';

            for (var count = 0; count < len; count++) {
                randomNumber = Math.floor(Math.random() * 10);
                n += randomNumber.toString();
            }
            return n;
        }

        var value = randomNumber(13);

        var elText = value;

        qrcode.makeCode(elText);
    }

    makeCode();

});    
#qrcode {
  width:160px;
  height:160px;
  margin-top:15px;
}
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" id="main">
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" id="lifirst" class="active"><a target='_blank' href="#home" aria-controls="home" role="tab" data-toggle="tab">List</a></li>
        <li role="presentation" id="lithird"><a target='_blank' href="#editable" aria-controls="editable" role="tab" data-toggle="tab" onclick='transfer_new()'>Add New</a></li>
    </ul>
    <!--/ Nav tabs /-->

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home" style="margin-top:  10px;">
            IN THE NEXT TABA THE AR CODE
        </div>
        <div role="tabpanel" class="tab-pane" id="editable">

            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4">
                <div id="qrcode"></div>
            </div>=
        </div>
    </div>
</div>
Answer:1

Try adding $('#qrcode').html(''); as the first item in the .click(function(){}

Like this:

$('#lithird').click(function(){      

    $('#qrcode').html('');  // <---Add this, which should clear it out on the next click

    var qrcode = new QRCode("qrcode");

    function makeCode () {      

        function randomNumber(len) {
        var randomNumber;
        var n = '';

        for(var count = 0; count < len; count++) {
            randomNumber = Math.floor(Math.random() * 10);
            n += randomNumber.toString();
        }
        return n;
    }

    var value = randomNumber(13);
        var elText = value;

        qrcode.makeCode(elText);
    }

    makeCode();

});

Codepen for full review

Answer:2

You were missing a function transfer_new defined in your onclick that was causing a JavaScript error.

function transfer_new() {
    $('#qrcode').html('');
}

$('#lithird').click(function() {

    var qrcode = new QRCode("qrcode");

    function makeCode() {

        function randomNumber(len) {
            var randomNumber;
            var n = '';

            for (var count = 0; count < len; count++) {
                randomNumber = Math.floor(Math.random() * 10);
                n += randomNumber.toString();
            }
            return n;
        }

        var value = randomNumber(13);

        var elText = value;

        qrcode.makeCode(elText);
    }

    makeCode();

});
#qrcode {
  width:160px;
  height:160px;
  margin-top:15px;
}
#qrcode img {
    margin: 15px;
    border: 5px solid black;
}
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" id="main">
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" id="lifirst" class="active"><a target='_blank' href="#home" aria-controls="home" role="tab" data-toggle="tab">List</a></li>
        <li role="presentation" id="lithird"><a target='_blank' href="#editable" aria-controls="editable" role="tab" data-toggle="tab" onclick='transfer_new()'>Add New</a></li>
    </ul>
    <!--/ Nav tabs /-->

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home" style="margin-top:  10px;">
            IN THE NEXT TABA THE AR CODE
        </div>
        <div role="tabpanel" class="tab-pane" id="editable">

            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4">
                <div id="qrcode"></div>
            </div>=
        </div>
    </div>
</div>
Answer:3

Just clear the content before generating new

    function randomNumber(len) {
        var randomNumber;
        var n = '';

        for (var count = 0; count < len; count++) {
            randomNumber = Math.floor(Math.random() * 10);
            n += randomNumber.toString();
        }
        return n;
    }

    $('#lithird').click(function() {

            var value = randomNumber(13);
            $("#qrcode").html("");
            var qrcode = new QRCode("qrcode");
            qrcode.makeCode(value);

    });    
    #qrcode {
      width:160px;
      height:160px;
      margin-top:15px;
    }
    <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
    <script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <div class="container-fluid" id="main">
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" id="lifirst" class="active"><a target='_blank' href="#home" aria-controls="home" role="tab" data-toggle="tab">List</a></li>
            <li role="presentation" id="lithird"><a target='_blank' href="#editable" aria-controls="editable" role="tab" data-toggle="tab" >Add New</a></li>
        </ul>
        <!--/ Nav tabs /-->

        <!-- Tab panes -->
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="home" style="margin-top:  10px;">
                IN THE NEXT TABA THE AR CODE
            </div>
            <div role="tabpanel" class="tab-pane" id="editable">

                <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4">
                    <div id="qrcode"></div>
                </div>
            </div>
        </div>
    </div>
Answer:4

$(".generatetext").click(function(e) {
    e.preventDefault();
    var x =  randomNumber(13);
    $('#output').html('').qrcode(x);
});

 function randomNumber(len) {
            var randomNumber;
            var n = '';

            for (var count = 0; count < len; count++) {
                randomNumber = Math.floor(Math.random() * 10);
                n += randomNumber.toString();
            }
            return n;
        }
#output{border:1px solid #eee;min-height:200px;width:200px;}
.container{padding:10px;}
<link target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<div class="container">
  <form class="form-inline">
    <div class="form-group">
      <button class="btn btn-primary generatetext">Generate Random QR Code</button>
    </div>
  </form>
  <div class="container">
    <div id="output" class="text-center"></div>
  </div>
</div>
Answer:5

I have a problem with my code it has a running error I am trying to convert an object to an array list. In my code, I was trying to build an array inside an array! I was expecting to have a return ...

I have a problem with my code it has a running error I am trying to convert an object to an array list. In my code, I was trying to build an array inside an array! I was expecting to have a return ...

  1. convert object array to string array
  2. convert object array to int array
  3. convert object array to list
  4. convert object array to string array c#
  5. convert object array to string array java
  6. convert object array to string array javascript
  7. convert object array to list c#
  8. convert object array to string array powershell
  9. convert object array to array javascript
  10. convert object array to json javascript
  11. convert object array to int array c#
  12. convert object array to double array java
  13. convert object array to float array python
  14. convert object array to arraylist java
  15. convert object array to byte array c#
  16. convert object array to string array python
  17. convert object array to json java
  18. convert object array to primitive array java
  19. convert object array to string array typescript
  20. convert object array to char array in java

I have a react project that uses messaging, so I want the most recently added message to be displayed on the bottom. I've tried the 'reversed' property for HTML5 tags, but it doesn't seem to change ...

I have a react project that uses messaging, so I want the most recently added message to be displayed on the bottom. I've tried the 'reversed' property for HTML5 tags, but it doesn't seem to change ...

  1. reverse display order
  2. display flex reverse order
  3. display grid reverse order
  4. extend display reverse order
  5. display in reverse order python
  6. display array in reverse order java
  7. display string in reverse order java
  8. display array in reverse order
  9. display array in reverse order c++
  10. display array in reverse order javascript
  11. display inline-block reverse order
  12. display string in reverse order python
  13. display numbers in reverse order c++
  14. display string in reverse order c++
  15. display numbers in reverse order java
  16. display listview in reverse order
  17. display file in reverse order unix
  18. display string in reverse order
  19. display li in reverse order
  20. display vector in reverse order c++

I got a column with filter type textbox and i got filterrow enabled but i need the filter conditions dropdown to also appear next to the textbox because i need to be able to apply multiple conditions ...

I got a column with filter type textbox and i got filterrow enabled but i need the filter conditions dropdown to also appear next to the textbox because i need to be able to apply multiple conditions ...

So I have perused the similar questions in this vein but they all have syntax errors. I have checked my codes with the available answers but it doesn't seem to be a syntax error; but I keep getting ...

So I have perused the similar questions in this vein but they all have syntax errors. I have checked my codes with the available answers but it doesn't seem to be a syntax error; but I keep getting ...