Reputation: 4524
I would like to change the null
value of a select input to show the user that something is happening in the background.
By null
value option I mean the first option that is selected:
<option value="">Select</option>
The "Select" is the text I'd like to (attempt) to change to say something else.
Here is a link to a JsFiddle to show what I'm trying to do.
I thought perhaps I could change the value:
$('#colors').text('Loading Colors');
Or, perhaps I just need to create an option with a value of loading
at the end and have it say "Loading"
<option value="loading">Loading Colors</option>
Then just select that option while the ajax is working?
Upvotes: 1
Views: 146
Reputation: 1218
All answers are correct...
I will show how i do every time i need something like this...
I prefer remove all options and append one saying that is loading.. I do this, because if you fill your select with others options after your ajax request, and change it again, if you dont remove the options, they will chain...
I do something like this:
$('#colors option').remove();
$('#colors').append("<option>Loading...</option>");
Finddle: http://jsfiddle.net/bqosrrcm/4/
Upvotes: 1
Reputation: 3925
If you want to access to the option with value "" then do this using selector #colors option[value=""]
JSFiddle - http://jsfiddle.net/bqosrrcm/2/
Upvotes: 0
Reputation: 5982
I'm not 100% sure that I understand your question, but if what you want to do is change the text of the first option of the select, you need to target the option
and not the select
itself.
Your code edited :
$('#colors option').text('Loading Colors');
And the edited fiddle : http://jsfiddle.net/bqosrrcm/1/
Note : The code above will affect all the option
of the select
element, in this case it's not a problem since there is only one option, but you will have to edit the code if you want to target only one.
Upvotes: 1