Load data on Bower plugin for a progress bar - javascript

I recently came across bower a web-tool to develop a progress bar. I have implemented a progress bar as series of radio buttons aligned next to each other. The concept is to load data from a .edf file to the browser upon clicking the radio buttons. All these work fine before I apply the Bower scripts. When I make a transition from one radio button to another I would like to have an effect which shows a transition while clicking on each button. Can I get some advice here if I can achieve this by applying any of the bootstrap classes or to modify the code existing? The snippet I have added is not loading the Bower libraries, otherwise it would look similar to this.
$('.radios').radiosToSlider({ animation: true, });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"/>=
<script type="text/javascript" src="bower_components/radios-to-slider/dist/jquery.radios-to-slider.js"/>
<link rel="stylesheet" type="text/css" href="bower_components/radios-to-slider/dist/radios-to-slider.css"/>
<div class="radios">
<label for="option1" class="btn">
<input id="option1" name="options" type="radio" autocomplete="off" onchange="dataSegment(0)" checked>
</label>
<label for="option2" class="btn">
<input id="option2" name="options" type="radio" autocomplete="off" onchange="dataSegment(1)">
</label>
<label for="option3" class="btn">
<input id="option3" name="options" type="radio" autocomplete="off" onchange="dataSegment(2)">
</label>
<label for="option4" class="btn">
<input id="option4" name="options" type="radio" autocomplete="off" onchange="dataSegment(3)">
</label>
<label for="option5" class="btn">
<input id="option5" name="options" type="radio" autocomplete="off" onchange="dataSegment(4)">
</label>
</div>

Your problem is that you are using a URL that is local to a website. Notice that you have no protocol in the URL (https://, http://, etc). I did a little digging, and the URL you should be using is http://rubentd.com/bower_components/radios-to-slider/dist/jquery.radios-to-slider.js

Related

I'm trying to put a <button> inside an <input type=“radio”>'s <label> for mobile

I asked this question a month ago: I'm trying to put a <button> inside an <input type="radio">'s <label>
The answer I marked correct worked perfectly... for the desktop browsers I tested. Testing on my iPhone 6, both Safari and Chrome have the buttons unclickable.
Correct answer snippet copied below:
button {
pointer-events:none;
}
<h1>Choose A or B</h1>
<input type="radio" name="choice" value="A" id="a"><label for="a"><button type="button">A</button></label>
<input type="radio" name="choice" value="B" id="b"><label for="b"><button type="button">B</button></label>
Is there a solution that works for both smartphone AND desktop?
I could get rid of <input type=“radio”> and rewrite radio button behaviour in JavaScript from scratch, but I'm hoping I won't need to do that. Is there an easier way?
<h1>Choose A or B</h1>
<label>
<input type="radio" name="mode" value="create">
<span style="-webkit-appearance: button;">create table</span>
</label>
<label>
<input type="radio" name="mode" value="create">
<span style="-webkit-appearance: button;">create field</span>
</label>

How does the toggle button work with checkboxes?

I'm referring to the Toggle buttons with checkboxes which I don't understand. There we have the example (I have added some ids):
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input id="c1" type="checkbox" autocomplete="off" checked> Checkbox 1 (pre-checked)
</label>
<label class="btn btn-primary">
<input id="c2" type="checkbox" autocomplete="off"> Checkbox 2
</label>
<label class="btn btn-primary">
<input id="c3" type="checkbox" autocomplete="off"> Checkbox 3
</label>
</div>
I can click on the third button or use $('#c3').closest('.btn').button('toggle') to set the third button as pressed. That is visually okay. However, the checkbox input does not get the checked attribute, and that is what I'm missing. Why doesn't this happen automatically? Am I required to do this manually?
Update and solution:
As Marcos Pérez Gude revealed: The inspector of Firefox (or Elements in Chrome) doesn't show changes regarding the checked state of a checkbox. There you can modify or see other things but currently (Firefox 40) the checked state cannot be trusted. That was my fault.

Setting a radio button to checked in jquery not showing it as checked in view

On document ready I'm setting a radio button to checked, I want the user to see the button as highlighted/discolored. But nothing is showing in the view.
Here is my html. Nothing shows it as being checked in the view or HTML. It's the same color as all the other radio buttons.
<div class="btn-group" data-toggle="buttons" id="SpaceType">
<label class="btn btn-primary">
<input type="radio" name="typeoptions" id="0" autocomplete="off"> House
</label>
<label class="btn btn-primary">
<input type="radio" name="typeoptions" id="1" autocomplete="off"> Apartment
</label>
<label class="btn btn-primary">
<input type="radio" name="typeoptions" id="2" autocomplete="off"> Studio
</label>
<label class="btn btn-primary">
<input type="radio" name="typeoptions" id="3" autocomplete="off"> Other
</label>
</div>
Here is my jquery.
if ($("#YogaSpaceType").val() != "") {
var t = $("#YogaSpaceType").val();
var element = '#SpaceType.' + t;
//$(element).prop('checked', true);
$('input:radio[id=SpaceType][id=0]').prop('checked', true);
}
I tried both lines including the one that is commented out.
If I add 'checked' to the element like below the HTML shows it as checked but I see nothing in the view as checked, it still looks unchecked.
<input type="radio" name="typeoptions" id="0" autocomplete="off" checked> House
It looks like you want to change this a bit to be more like http://www.mkyong.com/jquery/how-to-select-a-radio-button-with-jquery/. The problem here is you are trying to use the input keyword in jquery, but your html is button groups.
From that page, the HTML is:
<input type="radio" name="sex" value="Male">Male</input>
<input type="radio" name="sex" value="Female">Female</input>
<input type="radio" name="sex" value="Unknown">Unknown</input>
and then the JS is $('input:radio[name=sex]')[2].checked = true;
If it's necessary to leave them as button groups, you'll need to change your JS line to be more like $("#0").prop('checked', true). You could also chain the div ids together like this: $("#SpaceType #0").prop('checked', true);
It was a little confusing, but the class attribute 'active' needs to be added to the label. Not the checked attribute. This is a little confusing but understood now.
$('input[type="radio"][id="0"]').prop('checked', true)
Multiple value check for id, will end up in 0 elements.

div disappears when page refreshed

Can't figure out why the below piece of code makes the textfield disappear upon page refresh (when 'No' radio button selected).
Also, after the page is refreshed the default radio button doesn't get selected.
Forcing refresh, fixes the problem, though.
Any ideas?
<html>
<body>
<div class="editfield">
<div id="field_1">
<label>
<input type="radio" checked="checked" name="radio-1" id="radio-1_id" value="Yes" onclick="document.getElementById('divUrl').style.display='none'">Yes
</label>
<label>
<input type="radio" name="radio-1" id="radio-2_id" value="No" onclick="document.getElementById('divUrl').style.display='block'">No
</label>
</div>
</div>
<div class="editfield" id="divUrl" style="display:none">
<label>Website URL</label>
<input type="text" name="X" id="X_id" value="" />
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<body onLoad="document.getElementById('radio-2_id').checked=false; document.getElementById('radio-1_id').checked=true;">
<div class="editfield">
<div id="field_1">
<input type="radio" checked="checked" name="radio-1" id="radio-1_id" value="Yes" onclick="document.getElementById('divUrl').style.display='none'">
<label for='radio-1_id'>
Yes
</label>
<input type="radio" name="radio-1" id="radio-2_id" value="No" onclick="document.getElementById('divUrl').style.display='block'">
<label for='radio-2_id'>
No
</label>
</div>
</div>
<div class="editfield" id="divUrl" style="display:none">
<label>Website URL</label>
<input type="text" name="X" id="X_id" value="" />
</div>
</body>
</html>
just a short recap:
1. on page refresh the div should disappear (all css and js and html that was dynamically set / added is removed) and the selected radio button should be the first (Yes)
2. tested this on all major browser and it works
3. still can't figure out why it wasn't working on Mozilla and IE without the JS refresh
I moved the radio buttons out of the labels to see if that impacted the refresh in any way and it didn't. Also, I removed an extra </div> that was in the original code.
The page refresh will initiate the page in its' original state. So the
style="display:none"
will be reactivated on the div and will be hidden and the "Yes" button will also be reenabled
what i did have a textarea insert number first ,0 make it readonly
then it will not disappear on refresh,to insert document.getElementById("demo").readOnly=false,and true to enable readonly

horizontal radio buttons using bootstrap

I'm trying to align radio buttons horizontally in a form, using bootstrap.
Without adding the bootstrap library, this code works:
<form id="test_form">
<div class="control-group">
<label for="Q1">First question</label>
<label for="Q1RB" class="radio">
<input id="Q1RB" type="radio" name="Q1RB" value="Almost never" class="radio inline">Almost never
</label>
<label for="Q1RB" class="radio">
<input id="Q1RB" type="radio" name="Q1RB" value="Sometimes" class="radio inline">Sometimes
</label>
<label for="Q1RB" class="radio">
<input id="Q1RB" type="radio" name="Q1RB" value="Often" class="radio inline">Often
</label>
<label for="Q1RB" class="radio">
<input id="Q1RB" type="radio" name="Q1RB" value="Almost always" class="radio inline">Almost always
</label>
</div>
</form
But after adding the bootstrap.js to the header, the radio buttons aren't aligned horizontally anymore, but vertically.
I'm using the last version of bootstrap (3.1.1)
Try using the radio-inline class in your radio labels (see this link).
This happens because, by default, bootstrap uses a stacked layout.

Categories

Resources