简体   繁体   中英

How to call function from value

I'm trying insert this value in text field in my app. It should look like this: player1@enigmania.cz where 1 is random number between 1 and 100. Problem is that i cannot find anywhere on web or documentation how to call function from within value. The part of code looks like this:

function rand(min, max) { return Math.floor(Math.random() * 101);
}

function loginNoreg(e) {
$.txtName.value="player"+"rand"+"@enigmania.cz";

This gives just playerrand@enigmania.cz and not player1@enigmania.cz as I need. Thanks for any ideas how to do this.

Just call the function inline, without quotes. With quotes it is just a string.

$.txtName.value= "player" + rand() + "@enigmania.cz";

In order to use your min/max you want, provide the values in the line above and adjust your function like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM