Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting value of a dropdown and changing it onload

Status
Not open for further replies.

rkoya

IS-IT--Management
Jul 12, 2004
57
GB
Hi,

I was wondering if anyone could help, basically i wanted to get the value of a drop down box and change it onload.

This is my html:

<SELECT name="24FromTime" CLASS="DROPDOWN" SIZE="1" >

<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option selected value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="02:30">02:30</option>
<option value="03:00">03:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>

</select>

As you can see 01:30 is selected, I want to change that to 04:00 when page loads.

Can anyone help??

Thanks
 
add this to your head:

Code:
<script type="text/javascript"><!--
window.onload = function() { 
    var s = document.getElementById("mySelect");
    s.selectedIndex = s.options.length - 1;

};
//--></script>

and make sure your select box has the ID of "mySelect".



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for that, I have been reading through a lot of javascript that is hard coded to the site i am working on which I have no control over, basically the time is put forward 12 hours as of the current hour. Eg.

if it is 13.30 it will change time to 01:30
if it is 14:30 it will change time to 02:30.

Obviously the code you have supplied overrides that but is there a way to just say that when page loads have value at "04:00" and nothing else.

Thanks
 
actually, I seem to have resolved this problem, I have one other issue though :-(. I have a date on the site too and it is preselected to tomorrow's date, can I get that to change onload to 2 days in advance??

<select CLASS="DROPDOWN" name="slFromDay" onchange='modFDays(); addduration();'>
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="6" >6</option>
<option value="7" >7</option>
<option value="8" >8</option>
<option value="9" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
<option value="12" >12</option>
<option value="13" >13</option>
<option value="14" >14</option>
<option value="15" >15</option>
<option value="16" >16</option>
<option value="17" >17</option>
<option value="18" >18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" SELECTED>21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>
<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" >30</option>
<option value="31" >31</option>
</select>

Thanks
 
how do you make it select tomorrow's date? if you're already doing this one way, you should just change the way you're currently selecting the value to select the next value.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
This is bought in dynamically using javascript, unfortunately I do not have access to the code for me to change it. I can copy and paste the code on here tomorrow if that is ok.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top