Change switch (checkbox) state programmatically

Get help with using Metro 4 components
Post Reply
bambirra
Posts: 9
Joined: Mon Aug 13, 2018 6:20 pm
Status: Offline

Change switch (checkbox) state programmatically

Post by bambirra » Tue Apr 02, 2019 12:01 am

Hi,

I'm trying to change the state of the switch (checkbox) programmatically, but it is not working.

On the console I get the error: 'TypeError: checkbox is undefined'

Html

Code: Select all

<button onclick="changeCheckboxState()">test</button>
<br><br>
<input id="chkClose" name="chkClose" type="checkbox" 
	data-role="switch" 
	data-caption="Name" 
	data-material="true"
>
javascript

Code: Select all

function changeCheckboxState(){
	var checkbox = $("#chkClose").data('checkbox');
	checkbox.toggleState();
}
Sandbox example: https://sandbox.org.ua/ironclown/code/Vw6orhkdbv

thanks

User avatar
olton
Site Admin
Posts: 205
Joined: Mon Apr 09, 2018 6:19 pm
Location: Kiev, Ukraine
Status: Offline

Post by olton » Tue Apr 02, 2019 7:01 am

data('switch')

Post Reply