Of course JS could be used, or PHP.
Show us what you have already, or make a start here: http://lmgtfy.com/?q=show+random+number+on+button+click
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there!
This might look a little dumb, but I'm a beginner... I need to generate a random number by hitting a button and then display it within a text box. How can this be achieved? JS?
No need for ajax at all, it could be as simple as this: https://jsfiddle.net/ofpab4e9/1/
<button id="button" onclick="getElementById('random-number').value=Math.floor(Math.random()*10000)">Create Random Number</button>
<br>
<input id="random-number" value="" />
Please or to participate in this conversation.