php - Insert a button on a page with random number generation

I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random num

I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random number between 1-10000

I am quite new to Wordpress, I want to integrate some scripts to my Wordpress site to do this random number generation. For example I can call a php function when clicking that button. And the php code helps generate that random number and put it on the text box. but I don’t know where to begin. I googled that, but there isn’t a good reference for beginners at all

I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random number between 1-10000

I am quite new to Wordpress, I want to integrate some scripts to my Wordpress site to do this random number generation. For example I can call a php function when clicking that button. And the php code helps generate that random number and put it on the text box. but I don’t know where to begin. I googled that, but there isn’t a good reference for beginners at all

Share Improve this question asked Dec 9, 2019 at 4:57 gudakogudako 1113 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

all thing you have to do is use javaScript function

JavaScript Example:

var random_number = function(){
    return Math.floor(Math.random() * 10000) + 1;
};
document.getElementById('button_text').onclick = function () {
    document.getElementById("input_box").innerHTML = random_number();
};

jQuery Example:

$.randomBetween(0,10000);

In Jquery we can written as,

jQuery('body').on('click', '#button_text',function(){
    var minNumber = 1;
    var maxNumber = 10000;
    var randomNumber = randomNumberFromRange(minNumber, maxNumber);
    jQuery('#input_box').val() = randomNumber;

});
function randomNumberFromRange(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744925914a4601434.html

相关推荐

  • php - Insert a button on a page with random number generation

    I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random num

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信