2

I have a select box with some values. Upon clicking on a button, I want to remove the selected attibute for whichever option value has this property. Basically i want to reload the select box. I do not use jquery so is there any way in pure javscript to get it done?

I asked it in a different post because all answers relating to the post were in Jquery and i want to do it in javascript only.

I used removeAttribute function as

document.getElementById('selectboxID').removeAttribute("selected")

but it is not working.

user596502
  • 417
  • 3
  • 10
  • 22
  • Do you want to unselect any option or do you want to reset it do whatever option was selected when the page loaded? – Felix Kling Oct 29 '14 at 15:29
  • actually wanted to reload select box on clicking on Toggle off button and it should be preserved if the refresh/reload the page jsfiddle : http://jsfiddle.net/07530w5n/2/ – user596502 Oct 29 '14 at 15:40
  • The accepted answer (mine) in the duplicate also provides a non-jQuery solution. Note however that the only jQuery specifics in that answer is how to select the elements, not how to reset them. I assume you know how to select the option elements without jQuery. – Felix Kling Oct 29 '14 at 16:07

1 Answers1

2

According to : http://www.w3schools.com/jsref/prop_select_selectedindex.asp

document.getElementById("selectboxID").selectedIndex = -1;

Should do the trick

yunandtidus
  • 3,847
  • 3
  • 29
  • 42
  • Thank you for the response . By default if there are no selected attribute then Project.. option should be visible..check out here: http://jsfiddle.net/07530w5n/2/ – user596502 Oct 29 '14 at 15:46
  • Then instead of selecting `-1` which is nothing, select your Project index. No ? – yunandtidus Oct 29 '14 at 16:09