Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Else/If Javascript Function To Display A Page

Hi, 

 

I would like to create a toggle button, with options yes and no, that allows the user to decide if they want the welcome page displayed every time they open the app. 

 

<p>Display This Page On Launch?</p>

<div data-bb-type="toggle" data-bb-on="Yes" data-bb-off="No" onchange="welcome2();"></div>

 

This would be using bbui, https://github.com/blackberry/bbUI.js/wiki/Toggle-Buttons but I do not know how to code an else/if javascript function to allow the user to click yes or no and then the welcome page to be available or not displayed based on their choice.

 

Any help would be great, thanks Smiley Happy

New Developer
Posts: 17
Registered: ‎01-08-2013
My Device: Playbook
My Carrier: wifi

Re: Else/If Javascript Function To Display A Page

You should give your div an id, lets says button1. . In your javascript code, check for the value of the

 

 

 

document.getElementById("button1").value

 

and use If() else statement.

 

My suggestion assumes plain old javascript. If you are using other libraries like jquery..the syntax will vary, but you get the idea (i hope Smiley Happy)

Highlighted
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: Else/If Javascript Function To Display A Page

[ Edited ]

Ah right, okay. So, would this work?

 

<div id="button1" data-bb-type="toggle" data-bb-on="Yes" data-bb-off="No" onchange="localStorage.welcome = this.value"></div>

 

Javascript

 

function welcome2(){
document.getElementById("button1").value
if (localStorage.getItem('welcome') === null) {
bb.pushScreen('welcome.html', 'welcome');}
else
bb.pushScreen('menu.html', 'menu');
}

 

Or is there something else that I need to add in there? Thanks Smiley Happy