Avatar of James Rodgers
James Rodgers
Flag for Canada

asked on 

get defaultSelected for a drop down list and over write with latest selection

i have the following, a simpified version of the actual code,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

function getvalues(obj){
      alert([obj.name, obj.options.selectedIndex, obj.options.defaultSelected]);


<form name="frm">

<select name="sel" onchange="getvalues(this);">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5" selected="selected">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
<input type="reset" value="r">



teh first time i make a selection teh third value is blank, despite there being a selected value in the dropdown, however on subsequent changes teh third value holds the previously selected item.
i need to be able to determine teh value every time, particularly the FIRST time (need to have) the onchange event occurs and to overwrite the defaultSelected(nice to have) so that a reset will go to the last item selected not the item marked as selected on page load

Avatar of undefined
Last Comment
James Rodgers

8/22/2022 - Mon