Event on selection from dropdown - dropdown

<select (change)="f1()">
<option value="a">Option1</option>
<option value="b">Option2</option>
</select>
lets say user selects option2 from dropdown, then f1() will be executed as value of dropdown has changed and i am listening to change event. now again users clicks on dropdown and selects option2, in this case value of dropdown is not changed, so f1 is not executed. now i want f1 to be executed each time users selects some value from dropdown, no matter value has changed or not.

A simple workaround is using onclick, your f1() will fire each time you click the drop down.
here is an example
<select id="mySelect" onclick="myFunction()">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<p id="demo"></p>
<script>
var clicks = 0;
function myFunction() {
clicks++;
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x + " Clicks" + clicks;
}
</script>

Related

Change link href depending on drop-down value

I have a button witha a href link:
My button
Then I have 3 drop-down (select) inputs, lets call them A, B & C
Depending on what the users choose, I want the link to be changed as this
My button
All three drop-downs will be Required
Find the following snippet useful. Handle the default values for the query params.
<select id="a" onchange="changeUrl()">
<option value="a1">a1</option>
<option value="a2">a2</option>
</select>
<select id="b" onchange="changeUrl()">
<option value="b1">b1</option>
<option value="b2">b2</option>
</select>
<select id="c" onchange="changeUrl()">
<option value="c1">c1</option>
<option value="c2">c2</option>
</select>
<a id="test" href="mysite.com">My button</a>
<script>
function changeUrl(){
let url="mysite.com?a=";
let a= document.getElementById('a').value;
url+=a+"&b=";
let b=document.getElementById('b').value;
url+=b+"&c=";
let c=document.getElementById('c').value;
url+=c;
document.getElementById('test').href=url;
}
</script>
</body>

How to Reset Select Drop down in VueJs

I am new in vue js please help.
I have two dropdowns and that that dropdown create from loop
<select v-if="tour.city_expert == 2" v-model="selected[index]" class="form-control" :id="'city_expert_both'+index" v-on:change="intiTourCityExpert(index, $event)" :disabled="tour.is_disable==true">
<option value="" selected>Select City Expert</option>
<option value="Guideinperson">Guide in person</option>
<option value="AudioGuide">Audio Guide</option>
</select>
I as per image I want reset dropdown if I uncheck the checkbox but only reset single row as I uncheck the checkbox.
I set v-model="selected[index]" on dropdown and set code on uncheck this.$set(this.selected, index, ''); but its not working.
Help
I ran into similar situation, and following worked for me.
And to rest try following anywhere - this.selectedStatus = '0';
<select id="item_status" class="form-control" v-model="selectedStatus">
<option value='0'></option>
<option value='1'>One</option>
<option value='2'>Two</option>
</select>
If I were you, I would do something like this:
Add an onchange event to the checkbox with its index:
#change="onChange(index)"
In the methods object define the function
onChange like this:
methods: {
onChange(index) {
this.selected[index] = ''
}
}
If you want to reset the value of dropdown on click on any other button or so, than just set it to null.
this.accountType = null;
My Dropdown:
<ejs-dropdownlist
v-model:value="accountType"
:dataSource="accountTypesData"
:select="accountTypeSelect"
placeholder="Select a type"
></ejs-dropdownlist>

How to stop Vue.js from selecting the first option in select option?

My Vue/Buefy app automatically selects the first option from the list:
<b-select model="form.cities[i].index"
v-on:input.once="analyt('City ' + i)"
#input="form.cities[i].name = cities[form.cities[i].index ['#attributes'].Name"
:id="'city-'+i"
:name="'city-'+i"
:required="i == 0"
>
<option
:value="index"
v-for="(city,index) in cities"
v-text="city['#attributes'].Name">
</option>
</b-select>
How do I avoid that? I just want empty field selected by default (or nothing to be selected at all)
Could you just add an empty option field? This should solve your problem.
<b-select model="form.cities[i].index"
v-on:input.once="analyt('City ' + i)"
#input="form.cities[i].name = cities[form.cities[i].index ['#attributes'].Name"
:id="'city-'+i"
:name="'city-'+i"
:required="i == 0"
>
<option selected></option>
<option
:value="index"
v-for="(city,index) in cities"
v-text="city['#attributes'].Name">
</option>
</b-select>
I solved this problem by making sure the first element in the populating array was my default (the one I wanted selected). Then I set the value of the select element to the default.
In my case, I was populating the drop down list based on selection of a different drop down.
First drop down
<select id="firstDropdown" #change="populateDropdown">
// options code ...
</select>
Drop down being populated by the first drop down.
<select id="populatedDropdown">
<option v-for:"item in items">
{{ item }}
</option>
</select>
In Component script
data: function() {
return {
items: []
}
},
method: {
populateDropdown() {
// fetch items from api and store in "array".
this.items = ['Default'].concat(array);
document.querySelector('#popualtedDropdown').value = 0;
}
I hope that makes sense and helps.
<option
value="none" selected disabled hidden>
</option>
This worked for me seamlessly.
Another option is
<option
selected>
</option>
which gives an empty first entry in the list which is a bit undesired.

VBA IE11 locking in a change to a dropdown value

I'm using VBA to open a website, login, and navigate to a certain page. There is a dropdown with 8 options.
I used this code to change the dropdown to the value I want, but it always reverts back to the default as I continue. How do I lock this change in?
Set Element = IE.Document.getElementsByName("date_range")
Element.Item(0).Value = "custom"
Here's the page code:
<div class="SelectInput">
<select class="SelectInput-select" name="date_range">
<option value="all_time">All Time</option>
<option value="today">Today</option>
<option value="yesterday">Yesterday</option>
<option value="this_month">Month to date</option>
<option value="last_month">Last Month</option>
<option value="this_year">Year to date</option>
<option value="last_year">Last year</option>
<option value="custom">Between...</option>
</select>
<div class="SelectInput-arrows">...</div>
</div>
Thanks,
you need to set the selected attribute .... ref: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option_selected

Back button causes dropdown to have different values

I have an ASP.Net MVC app, and when a user clicks a certain link, I do the following:
var orderID = returnStatus["Data"];
var url = '#Url.Content("~/OrderEntry/OrderDetail")?orderID=' + orderID;
window.location.href = url;
This works great, however, when I click the back button, my html dropdown changes from:
Zone: <select id="Zones" name="Zones" style="width: 150px"><option value="1">Zone 1</option>
<option value="2">Zone 2</option>
<option value="3">Zone 3</option>
<option value="4">Zone 4</option>
</select>
to this:
Zone: <select id="Zones" name="Zones" style="width: 150px"><option value="QUOTE">Quote</option>
<option value="SUBM">Submitted</option>
<option value="INPRD">In Production</option>
<option value="CANC">Cancelled</option>
<option value="COM">Complete</option>
<option value="CH">Credit Hold</option>
</select>
These statuses are defined in a dropdown later in the code, and I'm not sure why they have moved up to this dropdown?
Both of these dropdowns are populated from the model. It's almost as if the model is trying to re-generate this html, but the values are somehow incorrect?
Here is the Razor syntax:
Zone: #Html.DropDownList("Zones", Model.Zones, new { style = "width: 150px" } )
This doesn't appear to happen in Firefox or Chrome.
Apparently it had to do with the fact that my ID was called "Zones". I changed this ID to AcctManagerZones and everything is working fine now.
Edited: It appears this wasn't exactly the answer either. It apparently has to do with the way IE caches the page. I still got the same thing, until I turned page caching off, then it worked.