Page 1 of 1

is there any way to toggle on off using JavaScript?

Posted: Fri Nov 22, 2013 9:40 am
by Patrick Kelly

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...


is there any way to toggle on off using JavaScript?

Posted: Fri Nov 22, 2013 11:14 am
by Maryna Brodina

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


is there any way to toggle on off using JavaScript?

Posted: Sat Nov 23, 2013 2:14 am
by Patrick Kelly

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.


is there any way to toggle on off using JavaScript?

Posted: Sat Nov 23, 2013 7:30 am
by Alena Prykhodko

Hi Patrick, please post code you tried.


is there any way to toggle on off using JavaScript?

Posted: Wed Feb 11, 2015 11:21 pm
by Bruce Stuart

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


is there any way to toggle on off using JavaScript?

Posted: Fri Feb 13, 2015 3:03 am
by Yurii Orishchuk

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.


is there any way to toggle on off using JavaScript?

Posted: Fri Feb 13, 2015 3:09 am
by Bruce Stuart

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