Quick question…
Is it possible to create a button that when clicked, changes the value of a textbox on the same page to a random number between set parameters (eg between 1 and 20)?
Thanks
Quick question…
Is it possible to create a button that when clicked, changes the value of a textbox on the same page to a random number between set parameters (eg between 1 and 20)?
Thanks
Sure, it’s pure javascript. Smth like here:
export function button1_click(event) {
$w("#text3").text = (Math.floor((Math.random() * 20) + 1)).toString();
}
Thanks, I have adapted this to my page and it works.
Is it possible to set the limits of the random number based on a value entered by a user?
Eg A user, enters a number in a user input field, and this is used to set the maximum for the random number generator
Yes, of course, you can substitute 20 with value of textinput component
thanks completed!
Here is the code that I used, if someone else has the same query
export function playerSelector_click(event) {
//Add your code for this event here:
$w(“#randomNumber”).text = (Math.floor((Math.random() * $w(“#teamTotal”).value) + 1)).toString();
}
OK, so I am new to code. I have tried adding the javascript shown above to a webpage using ‘Embed HTML Code’, but it doesn’t work, the webpage just shows the code. Any clues what I am doing wrong?
Hi James,
The HTML widget was designed to accept HTML code (that may or may not include javascript code)
The code mentioned in this thread ( and the wix code forum in general) was designed for wix code
Learn more about Wix Code here .
Is this possible to do with strings in a list?
Hi Mikhail.
For the code you supplied for Eaton, is it possible to also incorporate letters and a hyphen into the output.
which would give me an ID consisting of (286732-BaGffq)
cheers Gary
Hi,
I’ve prepared this example for generating Random Number in Range as well as Random String using WixCode.
Source code and demo are here:
https://webiya.wixsite.com/rnd-number-example
Enjoy.
I enabled developer mode on my site but still i don’t know where to put this java script code… can you help me?
You can also shuffle records from a Data Collection easy.
https://www.wixshow.com/wix-code-library/Shuffle-Data-Records-in-Wix-Code
Hi everybody,
Is it possibly to connect the generator to my database, to generate random numbers expect those who are in my database?
Thank you and best regards
Similar question…how would one fill in a user input (Prefer boolean) value with a random four or five digit number. Or have a database field auto fill with such. Or maybe I am missing something else. I need to filter a dataset by a consistant field by another dataset field.
In image attached, I want the far left data (a bio of person), to be carried across the site for use with various repeaters. So need to filter dataset 2 which is the bio dataset by a field in dataset 1. So need a field that matches for each, but do not want it to be a user entered field necessarily, and definitely do not want them have to retype each type as could see errors, etc.
So thought a auto fill of a field in the bio…that then carries over to any other inputs created by user later would then match as can set up each field to autofill from that first bio field created at the beginning. Make sense? Or is there a totally better direction I could take to achieve? @mikhail-spirin-wix