+ 3
[SOLVED] Revert the original values of <select> dropdown
There is a dropdown like this: <div> <span>Best Mobile Browser</span> <select> <option>Chrome</option> <option>Firefox</option> <option selected>Via</option> </select> </div> And when the user changes the value and click the revert button, it should revert all the option values to default (defined by selected attribute) My code: https://code.sololearn.com/W1v7qvKroeEQ/?ref=app
14 Respostas
+ 6
Ohhh, I didn't know there's a way to reset in form. Can you explain how..?
+ 5
all inputs are reverted to normal on clicking revert button...
https://code.sololearn.com/WdA0Vb6M1C25/?ref=app
+ 5
I guess the only way to do is what I have done, I had looked on
Google and stack. This is what I got
+ 5
Maybe Ipang
+ 4
Wow... that's great...
It's new to me, I also learned a lot. Thank you
+ 3
March Zucherberg
If we use a form, we'd only need to put a reset button to reset all form elements to default, no extra code necessary. But I suppose you have a reason to do this manually.
+ 3
My idea would be something like
<form>
<select> ... </select>
<!-- more elements here ... -->
<input type="reset" value="Revert" />
</form>
But maybe March has his own concerns that this doesn't suit the purpose.
+ 3
March Zucherberg
I don't know what you mean by "can take more control over it" but if it works for you then all is OK đ
+ 2
Ipang Steve Sajeev I could use the form and reset button method, but I already got 10 indentation spaces upto my <select> block and adding form tag adds 2 more to itđ. So, I prefer using JavaScript as it is working as expected by me and also, I can take more control over it using JS.
Thank you for your answers.đđ
+ 1
Steve Sajeev can't we do it by checking the 'select' attribute.
Using this method, I need to define the value for every dropdowns, this makes the process lengthy and also harder to manage.
+ 1
Richmond Osafo Akoto to use what?
0
I also thought so, but after lot of try and research, I did it.
See my updated code.
https://code.sololearn.com/WiAgf326Drh9/?ref=app
0
Html
- 2
Guys help me to use it