0

I have 1 dropdown box[year], 2 text box [startDate, endDate], whenever user select year from dropdown menu then text boxes startDate should auto populate to 01/01/+year and endDate to 12/31/+year. Below mentioned script works fine in Firefox but in IE getElementById('ff5').value is not working, any suggestions ?

My script:

<script>
function autoPopulateDate(value, startDt,endDt){
      document.getElementById(startDt).value='01/01/'+value;
      document.getElementById(endDt).value='12/31/'+value;
}
</script>

HTML Code:

<tr>
    <td>
        <select onchange="autoPopulateDate(this.value,'ff5','ff6')" size="1" name="ff4" id="ff4"><option value="">--&gt;select value&lt;--</option><option value="2005">2005</option>
        <option value="2006">2006</option>
        <option value="2007">2007</option>
        <option value="2008">2008</option>

        <option value="ALL">ALL</option>
        </select>
    </td>
</tr>
<tr>
    <td ><font class="rtabletext">Savings Start Date: </font></td>
    <td >
        <input type="text" value="" name="ff5" id="ff5" maxlength="50" size="10" class="text">
    </td>
</tr>
<tr>
    <td><font class="rtabletext">Savings End Date: </font></td>
    <td>
        <input type="text" value="" name="ff6" id="ff6" maxlength="50" size="10" class="text">
    </td>
</tr>
Rachel
  • 100,387
  • 116
  • 269
  • 365

1 Answers1

1

IE [at least some versions and rendering modes] wants you to access form members via the forms collection.

document.forms['someform'].elements['someelement'].value

Alternatively, you can use some ajax library (e.g. http://www.asp.net/ajax ) and use that libraries element retrieval method since those usually take browser compatibility stuff into account...

$get('element')
KristoferA
  • 12,287
  • 1
  • 40
  • 62
  • @KristoferA No, that's not necessary, the code works just fine. See @mu's fiddle, linked in his comment on the question. – no.good.at.coding Apr 28 '11 at 03:16
  • +1, Strangely, it worked for me now if am trying to access using document.forms['someform'].elements['someelement'].value, thanks KristoferA – Rachel Apr 28 '11 at 03:21
  • @Rachel nothing strange, just a browser compatibility quirk. It is possible (even likely) that later versions of IE have been aligned with other browsers. In other words, your original code may work in IE8/IE9 (when in standards mode) but not in IE7/6/5/4/3 or even new browsers if the page is rendered in quirks or compatibility mode. – KristoferA Apr 28 '11 at 03:35
  • @Pointy Can you clarify what portions of my answer you think are incorrect, and why? – KristoferA Apr 29 '11 at 02:41
  • @KristoferA the "document.getElementById()" method works perfectly well in Internet Explorer, back at least to IE 6 and almost certainly to IE 5 as well. – Pointy Apr 29 '11 at 03:55