bar rating - wanting default selection to be no selection - html

From http://netboy.pl/demo/jquery-bar-rating/examples/ - I'm using the first rating system using 10 bars. However, I want the default to be no selected option at all (i.e. no bars). Right now the default selection is option #1 - any thoughts? I did try adding an empty option but all it did was add another bar to the front (for a total of 11 bars which is not what I want). I want the 10 bars but none highlighted/selected. Any thoughts?!?
<div class="input select rating-a">
<select class="example-a" name="content_rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>

Since you're using jquery you can do something like this:
$('.example-a').prop("selectedIndex", -1);
http://jsfiddle.net/GAXBf/

URL : http://netboy.pl/demo/jquery-bar-rating/examples/ (This url is not working)
If i am not wrong, you are using jquery bar rating like (http://antenna.io/demo/jquery-bar-rating/examples/).
In this jquery bar rating library, we can set no value selected by default on bar.
<script>
$('#rating').barrating('show', {
theme: 'bars-1to10',
deselectable: true
});
</script>
HTML:
<select id="rating">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
.
.
<option value="10">10</option>
</select>
Hope, It will resolve your problem.

In case its still relevant. You can add a empty Option.
<select id="rating">
<option value></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
This will give 5 stars with zero filled. Off course this will only work if there is no initial value defined.

<select id="example">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

Just in case anyone was wondering, in the latest version of the jQuery Bar Rating Plugin (v1.0.5) you can add the following option to do the trick:
<option disabled selected>Select an option</option>
So your select box will look something like this:
<select>
<option disabled selected>Select an option</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<!-- etc. -->
</select>

I was having the same issue as the original poster with jQuery Bar Rating (http://antenna.io/demo/jquery-bar-rating/examples/)
When called each option within the select field was transformed to a link wrapped in a div with a class of "br-widget"
I only wanted to display 5 stars for the user to choose from, however the amount of options in the select would determine how many star ratings would show on the screen. The solution I found was to add a "Please Select" as an option and then to hide this using jquery as shown below.
$(document).ready(function() {
$(\'#rating\').barrating({
theme: \'css-stars\'
});
//HIDE THE FIRST STAR OPTIONS
$(".br-widget a:first-child").css( "display", "none" );
});
<select name="rating" id="rating">
<option value="0">Please Select</option>
<option value="1">1 Star</option>
<option value="2">2 Stars</option>
<option value="3">3 Stars</option>
<option value="4">4 Stars</option>
<option value="5">5 Stars</option>
</select>

I had the same problem with this latest 2016 version and i solved it by adding this javascript AFTER the function call and now everything works (hope this help someone):
$(document).ready(function() {
// remove the selection on the dropdown menu
$("#rating").val([]);
// remove all "selected" css to show as "unselected" by default
$(".br-widget a").removeClass('br-selected');
// remove default "selected text", if any
$(".br-current-rating").empty();
});
Here is my full code:
<script>
// 5-star rating script
$(function() {
$('#rating').barrating({
theme: 'fontawesome-stars',
initialRating: null, // initial rating
showValues: false, // display rating values on the bars?
showSelectedRating: true, // append a div with a rating to the widget?
deselectable: true, // allow to deselect ratings
reverse: false, // reverse the rating?
readonly: false, // make the rating ready-only?
fastClicks: true, // remove 300ms click delay on touch devices?
hoverState: true, // change state on hover?
silent: false, // supress callbacks when controlling ratings programatically
});
});
$(document).ready(function() {
// remove the selection on the dropdown menu
$("#rating").val([]);
// remove all "selectec" css to show as "unselected" by default
$(".br-widget a").removeClass('br-selected');
// remove default "selected text", if any
$(".br-current-rating").empty();
});
</script>
<style>
.br-wrapper{
width: auto;
display: inline-block;
}
.br-widget{
width: auto;
}
</style>

Related

Selecting an option in drop down menu one determines list available in the second drop down menu

I want to make the contains of a second drop down menu dependent on what is selected in the the first. In my case wish to do it for a car selection option. i.e when the car make is selected this then populates the model drop down menu with the relevant models.
As there are a lot of makes of car I would like to keep it concise if possible I presume arrays of models for each make is the solution but how do implement this.
I have look at various solutions and cannot find a suitable answer to this, any suggestions/examples would be gratefully appreciated.
I am using jsp.
Make:<select>
<option value="audi">Audi</option>
<option value="bmw">BMW</option>
<option value="ford">Ford</option>
<option value="toyota">Toyota</option>
</select>
You could do it with some simple JS and css ( here is a JSFiddle: http://jsfiddle.net/N7Q57/1/)
Make:
<select name="cars" id="cars">
<option selected value="Choose">Choose</option>
<option value="Audi">Audi</option>
<option value="BMW">BMW</option>
<option value="Ford">Ford</option>
<option value="Toyota">Toyota</option>
</select>
<div id="brands">
<select class="audi">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select class="bmw">
<option value="3">3</option>
<option value="4">4</option>
</select>
</div
the jQuery
$("#cars").change(function () {
var string = "";
string = $("select#cars option:selected").text();
if (string == "Audi"){
$("#brands .bmw").hide();
$("#brands .audi").show();
$("#brands").show();
} else if (string == "BMW"){
$("#brands .audi").hide();
$("#brands .bmw").show();
$("#brands").show();
}
})
and the CSS:
#brands{
display: none;
}

How to show disable HTML select option in by default?

I am new to HTML and PHP and want to achieve a drop-down menu from the mysql table and hard-coded too. I have multiple select in my page, One of them is
<select name="tagging">
<option value="">Choose Tagging</option>
<option value="Option A">Option A</option>
<option value="Option B">Option B</option>
<option value="Option C">Option C</option>
</select>
Problem is now that user can also select "Choose Tagging" as his tagging but i only want to provide him to chose from available three. I used disable as
<select name="tagging">
<option value="" disabled="disabled">Choose Tagging</option>
<option value="Option A">Option A</option>
<option value="Option B">Option B</option>
<option value="Option C">Option C</option>
</select>
But now "Option A" became the default one. So i want to set "Choose Tagging" as by default and also want to disable it from selection. Is it a way to do this. Same thing need to be done with other select which will fetch data from Mysql. Any suggestion will be appreciable.
use
<option selected="true" disabled="disabled">Choose Tagging</option>
Use hidden.
<select>
<option hidden>Choose</option>
<option>Item 1</option>
<option>Item 2</option>
</select>
This doesn't unset it but you can however hide it in the options while it's displayed by default.
In HTML5, to select a disabled option:
<option selected disabled>Choose Tagging</option>
Electron + React.
Let your two first options look like this.
<option hidden="true">Choose Tagging</option>
<option disabled="disabled" default="true">Choose Tagging</option>
First to display when closed.
Second to display first when the list opens.
I know you ask how to disable the option, but I figure the end users visual outcome is the same with this solution, although it is probably marginally less resource demanding.
Use the optgroup tag, like so :
<select name="tagging">
<optgroup label="Choose Tagging">
<option value="Option A">Option A</option>
<option value="Option B">Option B</option>
<option value="Option C">Option C</option>
</optgroup>
</select>
Another SELECT tag solution for those who want to keep first option blank.
<label>Unreal :</label>
<select name="unreal">
<option style="display:none"></option>
<option>Money</option>
<option>Country</option>
<option>God</option>
</select>
<select name="dept" id="dept">
<option value =''disabled selected>Select Department</option>
<option value="Computer">Computer</option>
<option value="electronics">Electronics</option>
<option value="aidt">AIDT</option>
<option value="civil">Civil</option>
</select>
use "SELECTED" which option you want to select by defult.
thanks
selected disabled="true"
Use this. It will work in new browsers
we can disable using this technique.
<select class="form-control" name="option_select">
<option selected="true" disabled="disabled">Select option </option>
<option value="Option A">Option A</option>
<option value="Option B">Option B</option>
<option value="Option C">Option C</option>
</select>
If you are using jQuery to fill your select element, you can use this:
html
<select id="tagging"></select>
js
array_of_options = ['Choose Tagging', 'Option A', 'Option B', 'Option C']
$.each(array_of_options, function(i, item) {
if(i==0) { sel_op = 'selected'; dis_op = 'disabled'; } else { sel_op = ''; dis_op = ''; }
$('<option ' + sel_op + ' ' + dis_op + '/>').val(item).html(item).appendTo('#tagging');
})
This will allow the user to see the first option as a disabled heading ('Choose Tagging'), and select all other options.
this should help....:)
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<option value=""selected="true" disabled="disabled"> Select</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
This will hide the option for you this easier that to make a other dropdown box
<option selected="true" disabled="disabled">Choose Tagging</option>
You can set which option is selected by default like this:
<option value="" selected>Choose Tagging</option>
I would suggest using javascript and JQuery to observe for click event and disable the first option after another has been selected:
First, give the element an ID like so:
<select id="option_select" name="tagging">
and the option an id :
<option value="" id="initial">Choose Tagging</option>
then:
<script type="text/javascript">
$('option_select').observe(click, handleClickFunction);
Then you just create the function:
function handleClickFunction () {
if ($('option_select').value !== "option_select")
{
$('initial').disabled=true; }
}

automatically position to an option in a drop down select box

how to position to an option in a select box when opened but the initial value should be empty?
ex:
<select>
<option value="" disabled selected style="display:none"></option>//<--- Initial value
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option> // <--- Automatically points here when opened
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
</select>
http://jsfiddle.net/vcGrr/
Using Jquery it is simple enough:
$("select").focus(function(){
$("select option").filter(function() {
return $(this).text() == "2014";
}).prop('selected', true);
});
Thanks for pointing out that my fiddle did not match the code - correct fiddle is above
Did you mean..
<option value="2014" selected>2014</option>
Set id to your <select> tag
<select id="ddl">
At the end of document add javascipt
<script type="text/javascript">
var firstclick=0;
document.getElementById("ddl").onclick=function(){
if(firstclick==0){
document.getElementById("ddl").selectedIndex=11;
firstclick=1;
}
}
</script>
Here is a jQuery version: jsfiddle
Relevant HTML:
<select>
<option value="" disabled selected style="display:none"></option>
...
<option id="2014" value="2014">2014</option>
...
</select>
jQuery:
var oldValue = null;
$( function ()
{
$('select').click(function(){
var s = $(this);
val = s.val();
oldValue = val;
if( val == null )
{
document.getElementById("2014").selected = true;
}
});
});
Update
Slightly modified version that contains purely jQuery selectors is here: jsfiddle.
Only change is to set 2014 to selected:
$("#2014").prop('selected', true);
Put selected on the option you want by default to be shown as follows-
<select>
<option value=""></option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014" selected>2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
</select>
Fiddle
You can’t. Implementations of select element work so that initially the default value is shown. Moreover, if a value like “2014” were shown but the default value were actually empty, it would seriously mislead users. You should reconsider the original problem (the unspecified problem that made you want to achieve something that cannot be achieved).
The behavior you describe could be simulated using CSS and JavaScript, by constructing something that looks like a select element but has been coded entirely differently.

Creating hidden text (and then subsequently showing it) in Bootstrap?

In the atoms tab of my Periodic Alchemy game, I have dropdowns that allow users to select how many protons, neutrons, and electrons they want in their atom. If a user strikes upon a certain atom, say, hydrogen, (1 Proton, 1 Neutron, 1 Electron), then the text "Hydrogen: 1" should appear signifying that you've discovered Hydrogen. Unfortunately, I can't find anything in the Bootstrap Information website: getboostrap.com
Other than Modals, which didn't suit my needs. Is there a solution to this?
This isn't a bootstrap feature. You can hide text with the CSS: display: none;. You can show it with the jQuery .show().
Does that fit your needs?
JSFiddle
HTML:
<select class="selection" id="protons">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select class="selection" id="neutrons">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select class="selection" id="electrons">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div class="atom hide" data-protons="1" data-neutrons="1" data-electrons="1">Hydrogen</div>
<div class="atom hide" data-protons="1" data-neutrons="1" data-electrons="2">Whatever</div>
JS:
$('.selection').change(function() {
$('.atom').addClass('hide');
$('.atom[data-protons=' + $('#protons').val() + '][data-neutrons=' + $('#neutrons').val() + '][data-electrons=' + $('#electrons').val() + ']').removeClass('hide');
});

Second HTML option load by default

In an HTML select element, is it possible to have the second option selected by default?
<select class="styled" onchange="location = this.options[this.selectedIndex].value;">
<option value="9u.html">Team 9u</option>
<option value="10u.html">Team 10u</option>
<option value="11u.html">Team 11u</option>
<option value="12u.html">Team 12u</option>
<option value="13u.html">Team 13u</option>
<option value="14u.html">Team 14u</option>
<option value="15u.html">Team 15u</option>
<option value="16u.html">Team 16u</option>
</select>
I would like the value "10u" to be in the select box when I load the page.
Use the selected attribute. Is google down?
<option value="10u.html" selected>Team 10u</option>