Hi this is my code working fine when you type the text it gets converted into an qr code but i want to make it automatic. I have a php function which generates random number, so instead of typing the text, the qrcode should be generated by the value of that function.

![enter image description here](https://i.stack.imgur.com/QiqQN.jpg)

This is my html page code:

```
    <!DOCTYPE html>
<body>
  <input id="text" type="text" value="http" style="width:80%" /><br />
<div id="qrcode"></div>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://davidshimjs.github.com/qrcodejs/qrcode.min.js'></script>

    <script src="js/index.js"></script>

</body>
</html>

```

This is my javascript function :

```
var qrcode = new QRCode("qrcode");

function makeCode () {      
    var elText = <?php echo random_str(6); ?> ;

    if (!elText.value) {
        alert("Input a text");
        elText.focus();
        return;
    }

    qrcode.makeCode(elText.value);

}

makeCode();

$("#text").
    on("blur", function () {
        makeCode();
    }).
    on("keydown", function (e) {
        if (e.keyCode == 13) {
            makeCode();
        }
    });

```

and this is the php function that i want to implement so that an random number will generate and qrcode will be formed on that basis

```
<?php

function random_str($length, $keyspace = '0123456789')
{
    $str = '';
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
        $str .= $keyspace[random_int(0, $max)];
    }
  return $str;
}

?>

```