Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

is there any way to toggle on off using JavaScript?

Essesntially, I want to be able to toggle the switch using JavaScript. If it's on, go off, if off, go on. Something like this:

Code: Select all

 if(Appery("useLoc").val() == "off"){ 
     Appery("useLoc").val("on").refresh(); 
 }else if(Appery("useLoc").val() == "on"){ 
     Appery("useLoc").val("off").refresh(); 
 } 

But that doesn't seem to work...

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

is there any way to toggle on off using JavaScript?

Hi, code looks correct and should work. Please check Toggle name. Do you switch on/off toggle which you get as a mapping result? Note on page will be hidden toggle used for mapping - this toggle you'll be using in your code. It's better to use this code:
preif(Appery("useLoc").val() == "off"){
Appery("useLoc").val("on").refresh();
} else {
Appery("useLoc").val("off").refresh();
}/pre

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

is there any way to toggle on off using JavaScript?

Thank you, this works! Now my only problem is that the toggle isn't invoking the service. I have an event set that reads useLocValue ChangeInvoke service. Now the toggle is changing (thanks again, by the way), but it doesn't follow the event procedure. Now, if I switch it manually, invokes the service. It just doesn't seem to respond to a JavaScript command, even though the conditions are met for the event to trigger.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

is there any way to toggle on off using JavaScript?

Hi Patrick, please post code you tried.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

is there any way to toggle on off using JavaScript?

I have a similar situation - I have a control that's a toggle. If the user is using the free version - I don't want them to be able to change the value ... so - in the value change event for this control - I've added this code:

if (!bpaid){
alert('In the free version - you cannot change the state of this control');
Appery( this.name).val('on');
Appery( this.name).refresh();
console.log('refreshed control');
}

I've also tried the suggestion above - and done Appery(this.name).val('on').refresh() - no change .

the value changes just fine - and the code and the debugger report the value as 'on' after this method runs - yet visually - it still appears on the 'off' state when toggled (undesirable)

I also can't via the debugger or via the code (i've entered all these commands in the debugger as well with the break point set on my console.log step above - and the control refuses to be controlled :-) . I've told it to hide() (it doesn't hide). I've set the attribute 'disabled' to disabled - the debugger even reports that this attribute is set to disabled - but low and behold - it is still alive and kicking and accepts input.

(PS - I've also used the control name specifically - Appery('toggle_copyme').val('on').refresh() to no avail as well )

Suggestions please???

Thanks
Bruce

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

is there any way to toggle on off using JavaScript?

Hi Bruce,

Here is correct code for your goal:

pre

if (!bpaid){
alert('In the free version - you cannot change the state of this control');
Appery( this.name).val('on');

Code: Select all

//Code to refresh toggle. 
Appery( this.name).flipswitch('refresh') 
console.log('refreshed control');  

}

/pre

Regards.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

is there any way to toggle on off using JavaScript?

Yurii, thanks !! I'll give it a try after a bit ( attending a HS soccer event now !! )

Return to “Issues”