Copy to the user what is in INPUT when you click the copy button

Asked

Viewed 21 times

0

I wanted to know how to create a button that when click, copy what is in the input

Input code and function:

Function:

    function geraSenha($tamanho = 18, $maiusculas = true, $numeros = false, $simbolos = false)
{
$lmin = 'abcdefghijklmnopqrstuvwxyz';
$lmai = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$num = '1234567890';
$simb = '!@#$%*-';
$retorno = '';
$caracteres = '';
$caracteres .= $lmin;
if ($maiusculas) $caracteres .= $lmai;
if ($numeros) $caracteres .= $num;
if ($simbolos) $caracteres .= $simb;
$len = strlen($caracteres);
for ($n = 1; $n <= $tamanho; $n++) {
$rand = mt_rand(1, $len);
$retorno .= $caracteres[$rand-1];
}
return $retorno;
}

Input:

<input name='AwardID' id='AwardID' type='text' maxlength='40' value='<?php echo geraSenha(18, true, false, false); ?>' readonly />

Knob:

<button id="copiarcodigo" type="button" onclick="" class="btn btn-default">Copiar código</button>
  • I was posting a reply with php, since there was no javascript in the request... @Bacco

  • @Magichat PHP has no way to access the Clipboard, it rolls on the server. How would that be? In principle it seems only a wrong tag, because the problem is JS.

  • Where are you talking about Clipboard ? in my view he wants to copy what is in the input and display pro user , no ?

  • Magichat by context, @Vinicius wants to copy the generated password to the user by clicking the button. That is, pro Clipboard. If it’s not that, just him [Dit] and explain better.

  • No problem... Favors multiple interpretations... If it manifests...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.