[SOLVED] Revert the original values of <select> dropdown | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

24th Nov 2020, 9:55 AM
Bibek Oli
Bibek Oli - avatar
14 Answers
+ 6
Ohhh, I didn't know there's a way to reset in form. Can you explain how..?
24th Nov 2020, 11:41 AM
Steve Sajeev
Steve Sajeev - avatar
+ 5
all inputs are reverted to normal on clicking revert button... https://code.sololearn.com/WdA0Vb6M1C25/?ref=app
24th Nov 2020, 10:06 AM
Steve Sajeev
Steve Sajeev - avatar
+ 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
24th Nov 2020, 11:11 AM
Steve Sajeev
Steve Sajeev - avatar
+ 5
Maybe Ipang
24th Nov 2020, 1:13 PM
Steve Sajeev
Steve Sajeev - avatar
+ 4
Wow... that's great... It's new to me, I also learned a lot. Thank you
24th Nov 2020, 11:36 AM
Steve Sajeev
Steve Sajeev - avatar
+ 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.
24th Nov 2020, 11:39 AM
Ipang
+ 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.
24th Nov 2020, 12:13 PM
Ipang
+ 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 👌
24th Nov 2020, 3:35 PM
Ipang
+ 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.🙏😊
24th Nov 2020, 3:16 PM
Bibek Oli
Bibek Oli - avatar
+ 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.
24th Nov 2020, 11:09 AM
Bibek Oli
Bibek Oli - avatar
+ 1
25th Nov 2020, 1:54 PM
Bibek Oli
Bibek Oli - avatar
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
24th Nov 2020, 11:29 AM
Bibek Oli
Bibek Oli - avatar
0
Html
5th Dec 2020, 7:55 AM
Richmond Osafo Akoto
Richmond Osafo Akoto - avatar
- 2
Guys help me to use it
25th Nov 2020, 9:57 AM
Richmond Osafo Akoto
Richmond Osafo Akoto - avatar