Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to add some default text to a HTML select box. The placeholder tag which works with input doesn't seam to work whit this one?
This works
<td><input type="text" placeholder="<?php echo $lang ['your_website']; ?>"/></td>
This doesn't work
<td><select type="text" placeholder="<?php echo $lang ['select']; ?>"/></td>
How can I fix this?
Are you looking for the selected attribute?
<select>
<option selected="selected">Select Country</option>
<option>United States</option>
<option>Mexico</option>
</select>
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
I think you can use it like this:
<select>
<option selected="selected">Default Option</option>
<option>1</option>
<option>2</option>
</select>
ie, use selected="selected" for the option you want to be the default.
or you may try this:
<select>
<option value="" disabled selected>Default Option</option>
<option value="1">1</option>
</select>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
hi i wants to apply a condition that if edit button is clicked then it show or hide another portion, i have applied the condition to do it but its not working:
$(document).ready(function() {
$("#edit-invited-btn").click(function() {
$(".edit-invited2").toggle();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-4" id="edit-invited2">
<select id="subjects" name="subjects" class="form-control select2" data-placeholder="Select Teacher" style="width: 100%;" multiple>
<option value="1" selected>1</option>
<option value="2">2</option>
</select>
</div>
<button class="pull-right" id="edit-invited-btn">Edit</button>
$(".edit-invited2") should be $("#edit-invited2"). In html, edit-invited2 is an id and not class.
$("#edit-invited-btn").click(function() {
$("#edit-invited2").toggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-4" id="edit-invited2">
<select id="subjects" name="subjects" class="form-control select2" data-placeholder="Select Teacher" style="width: 100%;" multiple>
<option value="1" selected>1</option>
<option value="2">2</option>
</select>
</div>
<button class="pull-right" id="edit-invited-btn">Edit</button>
$(".edit-invited").toggle();
There is no class named edit-invited in your code check once
If you want to toggle id="edit-invited" than replace
$(".edit-invited").toggle();
To
$("#edit-invited").toggle();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
how to include write-in option after drop-down option in html or javascript. As an example in the coding below,
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</select>
But the user's choice wasn't in the list given (e.g. Honda). so he/she can write their option in 'others' option.
Apologies for my english. Thanks in advance.
It seems you may want to use the <datalist> along with an <input>, which offers the functionality you're looking for; in the below example if the user types S then the option of Saab will show up which can be selected, or the user can continue to type to add a new option to the list:
<datalist id="carOptions">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</datalist>
<input type="text" name="automaker" list="carOptions" />
While this may not be precisely what you're hoping for it does offer the functionality you require without a dependence on JavaScript.
References:
* <datalist>.
* HTMLDataListElement.
You can easily do that with jquery.
$('#dropdownId').append($('<option>', {
value: -1,
text: 'None of them work for me..'
}));
And just handle the case when the value is -1
This question already has answers here:
Changing the selected option of an HTML Select element
(14 answers)
Closed 7 years ago.
<select name="cat1" class="form-control input-lg">
<option value="">All Businesses</option>
<option value="78">Deals</option>
<option value="46">Delivery</option>
<option value="45">Dispensary</option>
<option value="47">Doctor</option>
</select>
I know you could simply add the selected="selected" to the whatever option to make it default in the drop down. Currently the "All Businesses" option is the default one showing. I want the Dispensary option to show as default
<select name="cat1" class="form-control input-lg">
<option value="">All Businesses</option>
<option selected="selected" value="45">Dispensary</option>
<option value="46">Delivery</option>
<option value="47">Doctor</option>
<option value="78">Deals</option>
</select>
so basically I want that achieved but I am unable to edit the HTML code. Is there a way I can achieve it without touching the HTML?
$('select[name="cat1"] > option[value="45"]').attr('selected','selected');
This jQuery code will select that option element and add that attribute to it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've three select-box here. How can I make this.
<select class="form-control input-lg">
<option value="1">abcd</option>
<option value="2">efgh</option>
<option value="2">ijkl</option>
<option value="2">mnop</option>
</select>
<select class="form-control input-lg">
<option value="10">desk</option>
<option value="20">pen</option>
<option value="30">pc</option>
</select>
<select class="form-control input-lg">
<option value="100"></option>
<option value="200"></option>
<option value="300"></option>
</select>
Fundamentally this is an event driven question.
You want to populate the secondary select based on the first. You can do this with a jquery change event.
http://api.jquery.com/change/
On change, you initiate a callback function that populates the second select box, from there the population of the third is just the same concept.
A high level explanation is as such:
<select id="select1" class="form-control input-lg">
<option value="1">abcd</option>
<option value="2">efgh</option>
<option value="2">ijkl</option>
<option value="2">mnop</option>
</select>
<select id="select2" class="form-control input-lg">
</select>
<script>
$('#select1').change(function(){
alert("Something has changed");
// RUN SOME OTHER FUNCTION TO POPULATE THE SECOND SELECT BOX
// Grab the dom element of the second select
var select2 = $("#select2");
// iterate your data, here an array with an element, and populate the select element
$.each(['some data'], function() {
select2.append($("<option />").val("Something").text("Something else"));
});
})
</script>
Note: For this you will obviously have to include JQuery library in your code
This is also considerably inefficient, but the improvements would take too long to explain in such an open question.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to know how I can get information selected in a dropdown list when I press submit and then get the information displayed in a table within the same page.
I have created the dropdown list:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Please let me know how to display if for instance I select Volvo to be displayed within a td:
<table>
<tr>
<td></td>
</tr>
</table>
Thanks
Give your elements a unique ID attribute and it is very easy to do this:
Working jsFiddle example
HTML:
<select id="mySelect">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<table id="myTable">
<tr id="tr-1">
<td id="td-1"></td>
</tr>
</table>
<input id="mybutt" type="button" value="Click Me">
Javascript:
document.getElementById('mybutt').onclick = function() {
var selcar = document.getElementById('mySelect').value;
//alert(selcar);
document.getElementById('td-1').innerHTML = selcar;
};