I'm making a dropdown menu in HTML and was trying to figure out how to pre-select a drop down value when the page loads. I've tried the following, using the selected option to indicate what value I want to be the default upon load. Though, this doesn't seem to work and I still end up with the first option being the default. I'm sure it's really simple but is there
<select selected="3">
<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>
</select>
Rather than manually put it in the <option value> tag, since these options are being generated via a loop, is there a way in the <select> tag to indicate what option should be defaulted? Thanks.
Use the selected property of the <option> you want selected by default:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
You can set that property programatically, if you update your question to include how you are generating, I can update this to show you how.
Related
Is there an Emmet abbreviation for HTML element option, where the goal is to display this:
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
.
.
.
it is possible to get this result with this abbreviation
<!-- option[value="$"]{$}*3 -->
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
I have a code for select-menu like this.
<select class="custom-select">
<option value="">Select from the list</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
I want to style the drop-down like the following:
I am wondering how can I achieve this with only CSS.
NOTE: I am using bootstrap select-menu.
I notice that if you add multiple to a select element then all of the options are shown, while without multiple the element has a drop down button. I would like to have the drop down button and then be able to select multiple items from the drop down list. Is this possible?
There's a jsfiddle here: http://jsfiddle.net/Z6KWr/3/
<select id="delete_dropdown" multiple>
<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>
</select>
Thanks
No, the dropdown cannot allow multiple selection. For doing so you have to use some other plugin which will allow multiple selection while looking like a dropdown.
There are some plugins which you can find here
https://code.google.com/p/dropdown-check-list/
http://www.erichynds.com/blog/jquery-ui-multiselect-widget
http://blogs.prakashinfotech.com/multi-select-dropdown-list-using-jquery-plug-in-chosen.html
This is not possible in HTML. If you're interest in jQuery plugins then check
Multiple Select in Chosen.js
or
Multi-Value Select Boxes in Select2.js
I've managed to make myself drop menu navigation with html <select>. I've encountered one problem, though.
My external links aren't working. Namely Youtube.
Here is the code:
<select ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="" selected="selected">Navigation</option>
<option value="index.html">Home</option>
<option value="detroitvideoproduction.html">Video Production</option>
<option value="locationsounddetroit.html">Location Sound</option>
<option value="videoeditingdetroit.html">Video Editing</option>
<option value="custommotiongraphicsdetroit.html">Custom Graphics</option>
<option value="demoreel.html">Demo Reel</option>
<option value="http://www.youtube.com/user/VideoDetroitMI?ob=0">You Tube</option>
<option value="http://vimeo.com/liveoutloudproductions">Vimeo</option>
<option value="dslrrentalsdetroit.html">Camera Rental</option>
<option value="lectrosonicsrentalsdetroit.html">Audio Rental</option>
<option value="griprentalsdetroit.html">Grip Rental</option>
<option value="camerasupportdetroit.html">Camera Support</option>
<option value="about.html">About Us</option>
<option value="contact.html">Contact</option>
</select>
As you can see I have 2 external links. One to Vimeo, the other to Youtube.
When you select Vimeo it works perfectly fine and takes you to the appropriate vimeo page,
but when you select Youtube, it does nothing at all.
I know the URL in the link is correct, I checked it before I posted this.
Anybody know why Youtube wont work when Vimeo will?
Well you're not going to want to hear this, but it worked fine for me... i copied and pasted the code and tested it with Chrome and it went to your page just fine.
You might want to change onChange with window.location.href=this.value
So, the correct code is:
<select onChange="window.location.href=this.value">
<option value="" selected="selected">Navigation</option>
<option value="index.html">Home</option>
<option value="detroitvideoproduction.html">Video Production</option>
<option value="locationsounddetroit.html">Location Sound</option>
<option value="videoeditingdetroit.html">Video Editing</option>
<option value="custommotiongraphicsdetroit.html">Custom Graphics</option>
<option value="demoreel.html">Demo Reel</option>
<option value="http://www.youtube.com/user/VideoDetroitMI?ob=0">You Tube</option>
<option value="http://vimeo.com/liveoutloudproductions">Vimeo</option>
<option value="dslrrentalsdetroit.html">Camera Rental</option>
<option value="lectrosonicsrentalsdetroit.html">Audio Rental</option>
<option value="griprentalsdetroit.html">Grip Rental</option>
<option value="camerasupportdetroit.html">Camera Support</option>
<option value="about.html">About Us</option>
<option value="contact.html">Contact</option>
</select>
Some browsers may be objecting to seeing a ? in the string in a select list. Try converting your YouTube URL using TinyURL. I haven't tested, but I'm guessing that will do the trick.
How do you get the selected option to be in view on page load?
<select name="whatever" size="5">
<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" selected>7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
If I understand you correctly, you want the item shown in the dropdown list to be the selected item when the page loads. By default behavior the selected view does in fact show "in view" on page load. What are you seeing that you do not expect?
note: your html should be
<option value="7" selected="selected">7</option>
to be a valid html tag.
All browsers I've tested (Firefox, Chrome, Opera and IE7) scroll the contents to display the selected option.
Edit: Windows XP