changing placeholder of an input via <option> [duplicate] - javascript

This question already has answers here:
jQuery change input text value
(6 answers)
Closed 7 years ago.
I need some help with changing the placeholder of an input via <select>,
I mean I need to change the placeholder of an input if the option of the <select> has been changed
My code:
<select id="select" name="se">
<!-- if this is chosen placeholder will be 'you have chosen option n1' !-->
<option value="1">option 1</option>
<!-- if this is chosen placeholder will be 'you have chosen option n2' !-->
<option value="2">option 2</option>
<!-- if this is chosen placeholder will be 'you have chosen option n3' !-->
<option value="3">option 3</option>
</select>
<input type="text" id="inp" name="choosen">

Try this :
$('select').on("change",function()
{
$('#inp').val("you have chosen option n" + $.trim(this.value));
}).change();
Example : https://jsfiddle.net/DinoMyte/zcL12b1u/1/

Related

How to submit value in <select><option> without submit button. [duplicate]

This question already has answers here:
Jquery submit select form when option is selected
(1 answer)
How to submit form on change of dropdown list?
(4 answers)
Closed 5 years ago.
This is my code:
<form action="?sort=SELECTEDVALUEHERE" method="GET">
<select>
<option value="1">Option 1 </option>
<option value="2">Option 2 </option>
<option value="3">Option 3 </option>
<option value="4">Option 4 </option>
<option value="5">Option 5 </option>
</select>
</form>
This is what i want:
If someone click on option 1, it will submit the form. I do not want to add a submit button
this one:
<input type=submit />
Call .submit() in <select>:
<select onchange="this.form.submit()">
Set id attribute for form element, and trigger submit event when select change event occurs.
$("select").change(function(){
$("form").submit();
}

HTML5 datalist only option value hidden [duplicate]

This question already has answers here:
How to display only the text in datalist HTML5 and not the value?
(3 answers)
Closed 5 years ago.
I want to hide datalist value. Am using this code
<input list="options" oninput="console.log(this.value);" />
<datalist id="options">
<option value="1">Product 1</option>
<option value="2">Product 2</option>
<option value="3">Product 3</option>
</datalist>
I mean in the inputbox this showing values and product 1
i need to show only product 1,2,&3...
hide value (1,2,3)
.
Note: Here am passing value 1,2,3 so i just want to hide that only
here my code https://jsfiddle.net/69u5Leoa/
You may want to use select, because for the select element, the user is required to select one of the options you've given.
For the datalist element, it is suggested that the user select one of the options you've given, but he can actually enter anything he wants in the input.
you can see this to get more information HTML Form: Select-Option vs Datalist-Option
<select id="options">
<option></option>
<option value="1">Product 1</option>
<option value="2">Product 2</option>
<option value="3">Product 3</option>
</select>
Value="<%# DataBinder.Eval(Container, "ItemIndex") %>" it can solution this problem

How to target selected attribute(in HTML option) in CSS or Javascript [duplicate]

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.

How to get clicked option value of a multiple select, fired by .change() event [duplicate]

This question already has answers here:
Get clicked option in multiple dropdown
(4 answers)
Closed 8 years ago.
I have a select multiple list:
<select id="List" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
I trigger the event on the select:
$("select#List").change(function() {
// do ajax stuff...
});
I need to get the value of the clicked option that fired the change event.
Example:
if the option 1 is already selected, and I select the "option 2" that triggers the .change() event, I want get the value of "option 2".
(I've already read this post Get clicked option in multiple dropdown, but it doesn't work for me).
What does not work for you, I've checked the answers in link which you posted and it works.
See working example on fiddle: http://jsfiddle.net/unkxt8h3/
The only thing here is, that the event is fired even when you deselect the option. But checking if it's selected or not should be easy peacy ;)
html:
<select id="List" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
JS:
$("#List option").click(function () {
var value = $(this).attr("value");
console.log(value);
alert(value);
});

Getting the value of option and display it on the select box [duplicate]

This question already has answers here:
How can I set the value of a DropDownList using jQuery?
(17 answers)
Closed 8 years ago.
Hi I know this was asked many times, I'm looking for a simple solution.
<select onchange="this.options[this.selectedIndex].value">
<option>--Select--</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
When a user select an option let's say One the select box would display the numerical 1.
Thanks in advance
Why don't you just use a numeral for the display option on each?
e.g. <option value="1">1</option>
(and take the inline javascript out entirely).
example: http://jsfiddle.net/79xvY/
This will set the actual innerHTML value of the select box, if that is what your goal is
<select onchange="this.options[this.selectedIndex].innerHTML=this.value">
<option>--Select--</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>

Categories

Resources