Page 1 of 2

Show random text when a button is clicked!?

Posted: Mon Apr 14, 2014 7:17 pm
by antonback89

Can i create a simple app the show random text strings when i press a button with appery.io?
I don't think i can do it now with the free plan but i want to know before i upgrade.

Let's say i have a list:

"Text 1"
"Text 2
"Text 3"

And when i press the button random text will be shown in a label box or so?

Sorry for my newbie questions =)


Show random text when a button is clicked!?

Posted: Mon Apr 14, 2014 7:47 pm
by Maryna Brodina

Hello!

Let's assume you have array with strings prevar arr = ["Text1", "Test2", "Test3"];/prethen the following code will show random element from array prevar min = 0, max = 2;
var rand = min - 0.5 + Math.random()*(max-min+1)
rand = Math.round(rand);
alert(arr[rand]);/pre


Show random text when a button is clicked!?

Posted: Mon Apr 14, 2014 8:01 pm
by antonback89

Hey! Okej is there any tutorial or so to see how to work with JavaScript? Or is it any easier way to do it? Do i need to upgrade to do what you said? :)


Show random text when a button is clicked!?

Posted: Mon Apr 14, 2014 8:05 pm
by Maryna Brodina

Here is JavaScript API documentation http://docs.appery.io/documentation/j...
No, you don't need to upgrade to use JS in app.


Show random text when a button is clicked!?

Posted: Tue Apr 15, 2014 12:04 pm
by antonback89

Seems to be pretty hard. So maybe i've to study a little bit of javascript to handle this. =/


Show random text when a button is clicked!?

Posted: Tue Apr 15, 2014 8:22 pm
by antonback89

My problem is that i don't really understand where i should write my javascript list or so? Should i create a new datasource or where do you think i should begin?

Thanks again!


Show random text when a button is clicked!?

Posted: Tue Apr 15, 2014 8:33 pm
by antonback89

Now it shows the text in a "pop-up" message.
My thought is this.
I have a label/text on my phone and when i press the button i want the label/text to change right in the app, without any pop-up boxes or so.
Is that possible?


Show random text when a button is clicked!?

Posted: Tue Apr 15, 2014 8:48 pm
by antonback89

One more question: Let's say i will put a big list with 100+ quotes or so and pick a random everytime someone press a button. Can i use the same method? What do i have to change in the code for that to work?


Show random text when a button is clicked!?

Posted: Tue Apr 15, 2014 9:00 pm
by Maryna Brodina

Hello!

You can call the following JS on button click http://docs.appery.io/documentation/w...
prevar arr = ["Text1", "Test2", "Test3"];
var min = 0, max = 2;
var rand = min - 0.5 + Math.random()*(max-min+1)
rand = Math.round(rand);
Appery('label_Name').val(rand);/prewhere label_Name is Label component name.


Show random text when a button is clicked!?

Posted: Wed Apr 16, 2014 6:36 pm
by antonback89

What does "var rand = min - 0.5 + Math.random()*(max-min+1)" do?
Is "var min = 0, max = 2;" the length of my list?

Or will the script take a random item? So if i only have 3 items the chance to get the same in a row is quite big right?