...

View Full Version : Copy dropdown selection to another dropdown?



tho
09-06-2011, 02:02 PM
Hello, I am completely new to HTML/JS/CSS, therefore I know very little.

I have two drop-down prompt controls with month names. One has just one value (say "July") and the other has all the months of the year ("January".."December"). The first prompt control is hidden on the page. How do I set the default selection of the second prompt control to the value present in the first prompt control? So, when the page is run, the second prompt control should automatically show "July".

I was reading up on the selectedIndex property (?), but I know that it won't work because I want Index 0 to be selected in the first control and Index 6 in the second, and I expect it to change every month (next month it will be index 7 that should be automatically selected).

If it matters, I am using IE8. Thanks!

Philip M
09-06-2011, 05:42 PM
If I understand you correctly, you simply want the current month to be selected in the drop-down.


<body onload ="showMonth()">

<form>
<select name = "months">
<option value = 1>January</option>
<option value = 2>February</option>
<option value = 3>March</option>
<option value = 4>April</option>
<option value = 5>May</option>
<option value = 6>June</option>
<option value = 7>July</option>
<option value = 8>August</option>
<option value = 9>September</option>
<option value = 10>October</option>
<option value = 11>November</option>
<option value = 10>December</option>
</select>
</form>

<script type = "text/javascript">
function showMonth() {
var d = new Date().getMonth();
document.forms[0].months.selectedIndex = d
}

</script>

If that is not what you want, please explain more clearly. What is the point of a select list with only one option? Especially if it is hidden! You can of course easily manipulate the selected month to be two months ahead or whatever.


When trouble arises and things look bad, there is always one individual who perceives a solution and is willing to take command. Very often, that individual is crazy.

tho
09-06-2011, 08:37 PM
Thanks for the reply. You're right that I want the current month, but I wanted help with a reporting application and "current month" for our database is July. I no longer have this requirement; thanks again though. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum