If I have 2 inputs, and in each of them I will write a name, how can I generate a random name from 2 input with javascript code by pressing a button?
1 answer
$("#btn").click(function() { var temp = Math.floor(Math.random() * 2); var randName = $("#inp" + temp).val(); alert(randName); }); <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <input type="text" id="inp0" /> <input type="text" id="inp1" /> <input type="button" id="btn" value="Click me!!!" /> </body> </html> - How will it be without jquery? - Asking
var btn = document.getelementbyid("btn");btn.onclick = function(){ var temp = Math.floor(Math.random() * 2);var inp = document.getelementbyid("inp"+temp);alert(inp.value);};Wrote from the phone ... there may be blots - Vitaly Shebanits
|
сгенерировать случайное имяso it’s chtoli - Vasya, Petya = Pesya? - Artem Gorlachev