473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

onchange date script

Dear All,
I am a learner of Javascript. I got an assignment as below. Could anyone give me a suggestion for fixing the function of "onChangeColumn4()".
The original requirement of the start date of this practice is 1985 09 20.
When user click different year and different month, then the "Index Number" will display different number. (actually, every season is the same index number".)
I used a data hierarchy approach to program it, but it seems not working very well.
If anyone can give me suggestion, I deeply appreciate.

Best Wishes!

Aleck

-----------------------------------------------------------------------
[HTML]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>

<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}

.style3 {
font-size: 24px;
font-weight: bold;
}

.style4 {
color: #660000;
font-size: 16px;
font-weight: bold;
text-decoration: none;
}
-->
</style>

<script>

function node(name, child){
this.name=name;
this.child=child;
}

function dataHierarchy(){

// before 1985
var b1985=new Array();
var i=0;
b1985[i++]=new node(" ", [" "]);

// 1985
var y1985=new Array();
var i=0;
y1985[i++]=new node(" ", [" "]);
y1985[i++]=new node("09", [" 71.3"]);
y1985[i++]=new node("10", [" 72.7"]);
y1985[i++]=new node("11", [" 72.7"]);
y1985[i++]=new node("12", [" 72.7"]);

// 1986
var y1986=new Array();
var i=0;
y1986[i++]=new node(" ", [" "]);
y1986[i++]=new node("01", [" 74.4"]);
y1986[i++]=new node("02", [" 74.4"]);
y1986[i++]=new node("03", [" 74.4"]);
y1986[i++]=new node("04", [" 75.6"]);
y1986[i++]=new node("05", [" 75.6"]);
y1986[i++]=new node("06", [" 75.6"]);
y1986[i++]=new node("07", [" 77.6"]);
y1986[i++]=new node("08", [" 77.6"]);
y1986[i++]=new node("09", [" 77.6"]);
y1986[i++]=new node("10", [" 79.8"]);
y1986[i++]=new node("11", [" 79.8"]);
y1986[i++]=new node("12", [" 79.8"]);



// year
var output=new Array();
var i=0;
output[i++]=new node(" ", b1985);
output[i++]=new node("1985", y1985);
output[i++]=new node("1986", y1986);
return(output);
}
dataTree=dataHierarchy();

//
function onChangeColumn3(){
updatePath();
}

//
function onChangeColumn2(){
form=document.theForm;
index1=form.column1.selectedIndex;
index2=form.column2.selectedIndex;
index3=form.column3.selectedIndex;
// Create options for column 3
for (i=0;i<dataTree[index1].child[index2].child.length;i++)
form.column3.options[i]=new Option(dataTree[index1].child[index2].child[i], dataTree[index1].child[index2].child[i]);
form.column3.options.length=dataTree[index1].child[index2].child.length;
form.column4.value="";
updatePath();
}

//
function onChangeColumn1() {
form=document.theForm;
index1=form.column1.selectedIndex;
index2=form.column2.selectedIndex;
index3=form.column3.selectedIndex;
// Create options for column 2
for (i=0;i<dataTree[index1].child.length;i++)
form.column2.options[i]=new Option(dataTree[index1].child[i].name, dataTree[index1].child[i].name);
form.column2.options.length=dataTree[index1].child.length;
// Clear column 3
form.column3.options.length=0;
form.column4.value="";
updatePath();
}

//
function updatePath(){
form=document.theForm;
index1=form.column1.selectedIndex;
index2=form.column2.selectedIndex;
index3=form.column3.selectedIndex;
if ((index1>=0) && (index2>=0) && (index3>=0)) {
text1=form.column1.options[index1].text;
text2=form.column2.options[index2].text;
text3=form.column3.options[index3].text;
form.path.value=text1+" ==> "+text2+" ==> "+text3;
} else
form.path.value="";
}

function onChangeColumn4(){
node ();
dataHierarchy();
form=document.theForm;
index1=form.column1.selectedIndex;
index2=form.column2.selectedIndex;

if ((index2 == "09") && (index1 == "1985"))
{
for (var d=20; d <=30; d++)
document.writeln("<option value=" + d + ">" + d + "</option>");
}

else {
for (var d=1; d <=31; d++)
document.writeln("<option value=" + d + ">" + d + "</option>");
}


}
</script>
</head>

<body>
<table width="94%" border="0" align="center">

<tr>
<td colspan="2">
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
</tr>

<tr>
<td colspan="2">
<form id="theForm" name="theForm" method="post" action="">
<table width="341" border="0" align="center" cellpadding="3" cellspacing="3" bordercolor="#000000">
<tr align="center" bgcolor="lightgrey">
<td width="173" height="25" bgcolor="#999999" class="style4">
<div align="center">
<u>Date of Acquisition</u>
</div>
</td>
<td width="147" bgcolor="#999999" class="style4">
<div align="center">
<u>Index Number</u>
</div>
</td>
</tr>

<tr bgcolor="white">
<td>
<div align="center">
<table align=center border=0>
<tr>
<td align=center>
<select name="column1" onChange="onChangeColumn1();">
<script>
for (i=0; i<dataTree.length; i++)
document.writeln("<option value=\""+dataTree[i].name+"\">"+dataTree[i].name);
</script>
</select>
</td>

<td align=center>
<select name="column2" onChange="onChangeColumn2();">

</select>
</td>

<td>

<select name="column4">
<option selected="selected"> </option>
<script>
onChangeColumn4 ();
</script>
</select>

</td>


<td align=center>
<div align="center"></div>
</td>
</tr>
</table>
</div>
</td>
<td>
<div align="center">
<select name="column3" size="1" onChange="onChangeColumn3();">
</select>
</div>
</td>
</tr>
</table>


</form>
</td>
</tr>
</table>
</body>
</html>[/HTML]
Mar 14 '07 #1
3 1402
acoder
16,027 Expert Mod 8TB
Changed title
Mar 14 '07 #2
acoder
16,027 Expert Mod 8TB
You can't call onChangeColumn4 like that. You will have to call it when one of the other select options onchange fires.
Mar 14 '07 #3
hi dear
if your mean is , you want show the Data of selected day , so why you dont give the actual day Data like it : ?

[HTML]
y1986[i++]=new node("12", ["01"," 79.8"]);
y1986[i++]=new node("12", ["02"," 75.5"]);
y1986[i++]=new node("12", ["03"," 80.3"]);
y1986[i++]=new node("12", ["10"," 71.2"]);
y1986[i++]=new node("12", ["23"," 72.6"]);
y1986[i++]=new node("12", ["30"," 70.8"]);
[/HTML]

best regards.
mh
Mar 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
1
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML =...
3
by: NewmanBT | last post by:
As you can see from the code below, several textboxes will be dynamically created and each will be tied to an org. The ChangeComment function should allow for an update to the database whenever...
1
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
2
by: a10392 | last post by:
Hi, I'am triyng to create a form where i have 2 comboBox and 2 textbox, when the selection changes on the first combo , the content of second also changes. i have to use onchange=form.submit() ...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
1
by: Kathy Burke | last post by:
Hi, I have a textbox and a calendar popup window. I got this from a posting (sorry, his name escapes me at the moment). It's nice and simple, so I like it, of course. Only problem I have is that...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.