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
@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.
– Bacco
Where are you talking about Clipboard ? in my view he wants to copy what is in the input and display pro user , no ?
– MagicHat
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.
– Bacco
No problem... Favors multiple interpretations... If it manifests...
– MagicHat