General discussion

Locked

Javascript dropdown change

By iheatseekeri ·
I'm sure this is probably very easy, but...
I have a list of different charts that can be viewed by the user.
Each chart is listed in a select list (there's about 30 charts, the select shows 10 at a time).
Below the main select is a dropdown select.
Each chart has a different initial starting year.
Depending on which chart a person selects, should change the starting year.
Right now I have a chart which has an initial year of 1967. Next to that is a chart that has an initial year of 1978. When I click on the '78 chart, the year drop down switches to 1978, but the years 1967-1977 move to the end of the list (after 2006, then 67-77 show up).
Question: how can I clear that from showing up?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by mindilator In reply to Javascript dropdown chang ...

show us your code, please...

Collapse -

by iheatseekeri In reply to Javascript dropdown chang ...

Sure thing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var today = new Date();
var tyear = today.getFullYear();
var i=0;

function show() {
if ((document.chartbook.category.selectedIndex == 12) || (document.chartbook.category.selectedIndex == 16) ||
(document.chartbook.category.selectedIndex == 19) || (document.chartbook.category.selectedIndex == 23))
document.getElementById('hideme').style.visibility='visible';

else
document.getElementById('hideme').style.visibility='hidden';

return true;
}


function getyear() {
var year;

if ((document.chartbook.category.selectedIndex == 0) || (document.chartbook.category.selectedIndex == 1)||
(document.chartbook.category.selectedIndex == 2) || (document.chartbook.category.selectedIndex == 3)){
year = 1967;
return year;
}
else if (document.chartbook.category.selectedIndex == 4) {
year = 1940;
return year;
}
else if (document.chartbook.category.selectedIndex == 5){
year = 1956;
return year;
}
else if (document.chartbook.category.selectedIndex == 6){
year = 1995;
return year;
}

else {
var today = new Date();
var current = today.getFullYear();
if (today.getMonth() <= 7)
year = current-1;
else
year = current-2;
return year;
}
}

function getcount(){
var year = getyear();
var today = new Date();
var endyear = today.getFullYear();
var count;
count = endyear-year+1;
return count;
}

function exchange(){
var i;
var count;
var year;

year=getyear();
count = getcount();

//set new values
for (i=0; i < count;i++){
document.chartbook.strtdate.options.value=year;
document.chartbook.strtdate.option

Collapse -

by iheatseekeri In reply to Javascript dropdown chang ...

//set new values
for (i=0; i < count;i++){
document.chartbook.strtdate.options.value=year;
document.chartbook.strtdate.options.text=year;
document.chartbook.enddate.options.value=year;
document.chartbook.enddate.options.text=year;
year++;
}
}
</script>
</head>
<body>
<form name="chartbook">
Category:<br />
<select name="category" size="7" onchange="show(); exchange();">
<optgroup label="Section A. Labor Force Data">
<option value='a1' selected="selected">Regular State UI Program Initial Claims </option>
<option value='a2'>Seasonally Adjusted Initial Claims </option>
<option value='a3'>Regular State UI Program Weeks Claims </option>
</optgroup>
<optgroup label="Section B. Solvency Data">
<option value='b1'>UI Program Outlays </option>
<option value='b2'>Average High Cost Multiples, US average </option>
<option value='b3'>Average High Cost Multiples, by State </option>
<option value='b4'>Maximum Taxable Wage Base </option>
<option value='b5'>Net Trust Fund in State Accounts </option>
</optgroup>
</select>
<br />

<div id="hideme">
State:<br />
<select NAME="states[]" multiple size="4">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AR">Arkansas</option>
<option value="AZ">Arizona</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
</select>
</div>

<div><strong>Starting year:</strong> <select name="strtdate">
<script>
var year=null;
year=getyear();
for (i=year;i<=tyear;i++){
document.write("<option value='+i+'>"+i+"</option>");
}
</script>
</select></div><br />
<div><strong>Ending year:</strong> <select name="enddate">
<script>
var year=null;
year=getyear();
for (i=year;i<=

Collapse -

by iheatseekeri In reply to Javascript dropdown chang ...

<div><strong>Ending year:</strong> <select name="enddate">
<script>
var year=null;
year=getyear();
for (i=year;i<=tyear;i++){
document.write("<option value='+i+'>"+i+"</option>");
}
</script>
</select></div>
</form>
</body>

Collapse -

by iheatseekeri In reply to Javascript dropdown chang ...

Entering the code butchered it a little bit there, but the general gist of it comes through.

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums