I realize this is really old at this point, but I am working in a really old legacy UI that we are trying to transition to Material design with as minimal impact as possible without a full re-write...
Your snippet works amazing for our need, however, as soon as we move the switches outside of the UL/LI pattern, they break... (no click response) if we toggle values programatically it works as expected... If we copy your template into ours they work fine though... I am at a loss as to what would be missing since there is no JS processing or anything that appears to be needed for this?
Any help would be greatly appreciated, thank you again for the amazingly simple MD switches :)
ktiedt () - 5 years ago - Reply 0
And now I feel like an idiot, when I modified the HTML for our templating system I included the name attribute but not the id attributes (which the for attribute is keyed to)... Sorry for the noise!
ktiedt () - 5 years ago - Reply 0
If the html is fixed it works, but if I inject html asynchronously (li elements to the ul) it does nothing, any idea why? Thanks in advance.
mmucino () - 5 years ago - Reply 0
What do i do to keep the toggle on/checked on page load. Like if an option is yes/selected i want the switch in on position when the page loads and off if its not selected.
O'Neil Fernandes () - 7 years ago - Reply 0
Not Working Please Help me
<script>
$('body').on('click','.chk',function(event) {
var flag;
if(this.checked)
{
var stt=confirm("Are You sure you want to perform this action??");
if(stt)
{
$(this).attr("checked",true);
flag=1;
}
else
{
$(this).removeAttr("checked");
}
}
else
{
var stt=confirm("Are You sure you want to perform this action??");
if(stt)
{
$(this).removeAttr("checked");
flag=0;
}
else
{
$(function(e){
//e.preventDefault();
e.stopPropagation();
$('.toggle:after').css('left','15px');
//$(this).attr("checked",true);
$(this).is(':checked')
});
}
}
});
</script>
<label>
<input type="checkbox" class="chk" checked=""/>
</label>
Hasmukh Baldaniya () - 8 years ago - Reply 0
Is there any way to "uncheck" the switches when one is "checked"? Example: When Default is checked, I want to "uncheck" all the others.
Matheus Reis Eidt () - 8 years ago - Reply 0
I'm trying to get the value of this checkbox using jQuery
$('#someSwitchOptionPrimary').val()
But this code ALWAYS return me value 'on'... so I wonder what's going on and have anybody else also seen this problem?
katie () - 8 years ago - Reply 0
Yeah, sorry for the short reply, I was working and didn't have time to explain. Glad you got it working.
mouse0270 () - 8 years ago - Reply 0
I have added this in a tabs.
It works with first tab not the other tab
Zahedul Alam () - 8 years ago - Reply 0
Hey.. This code is great. Can I use this in my project ? What kinda license does this port with ?
Anudeep Bulla () - 8 years ago - Reply 0
I like this. Would like to use it in a site where we are pushing the values in to use these in a checklist fashion. However, the input and label are being kicked down a line, they are not lining up with the text in the list-group-item. I just can't work out the issue, would you be able to provide a pointer please?
Lee Alderdice () - 8 years ago - Reply 0
if you can email (rmcintosh@remabledesigns.com) me I would be happy to help. I am not quite sure what you are trying to do some images of the code and what is happening would be useful. Or access to a demo site would be perfect.
mouse0270 () - 8 years ago - Reply 0
Sorry for the delay. I had it tucked inside a card-block in bs-4 alpha and there was a padding I just kept skipping over.
Lee Alderdice () - 8 years ago - Reply 0
Nice great work, here's another way to create buttons using materials http://www.tutorialspark.co...
vikas kumar (ВикаÑ) () - 9 years ago - Reply 0
How can I get the value for whether checkbox is switched on or off into another page using PHP?
Rashesh Bosamiya () - 9 years ago - Reply 0
It is just a fancy looking checkbox. You would use the checkbox value of "true" or "false"
mouse0270 () - 9 years ago - Reply 0
yes!! I want to determine the value into next page using PHP.
Rashesh Bosamiya () - 9 years ago - Reply 0
Assign a name and a value=1 to the input tag.
For example "<input id="someSwitchOptionDanger" name="my_checkbox" value="1" type="checkbox"/>"
Then in the PHP code:
Mikey King () - 9 years ago - Reply 0
It should turn a checkbox into a toggle like the ones you see on android devices. If you are just seeting a checkbox on the right hand side, what browser are using and what version is that browser
mouse0270 () - 9 years ago - Reply 0