Change
Main Topics
Browse All TopicsHi,
Here's my code that doesn't work.
function GetData()
{
//debugger
var YearArray;
var arrCount = 0;
var arrPeriod = new Array();
var arrPeriod = "|56|US Direct|2008|11|MBS Direct|2009|41|Direct|2007
//Populate arrPeriod
for(i=0;i<arrPeriod.length
arrPeriod[i];
}
//populate YearArray
var chk = document.getElementsByName
YearArray = new Array();
for (var i=0; i<chk.length; i++)
{
if (chk[i].checked)
{
var YearvalueArray = chk[i].getAttribute("value
YearArray[arrCount] = YearvalueArray[0];
arrCount++;
}
}
arrCount = 0;
//this part does not work
//here I have to say if the user checked years 2008 and 2009 then the
//chkPeriod[i] checkbox should have the value of 2008 and 2009 from
//arrPeriod
//the text should be from arrPeriod ("US Direct") and ("MBS Direc")
for (i=0;i<YearArray[i].length
{
if (arrPeriod[2] = YearArray[i])
document.form1.ChkPeriod[i
document.form1.ChkPeriod[i
}
//the screen look like this if the user checked 2008 and 2009
[] 2007
[X] 2008
[X] 2009
//here I should prompt the user with
[] US Direct
[] MBS Direct
}
</script>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
function GetsData()
{
debugger
var YearArray;
var arrCount = 0;
var arrPeriod = new Array();
var list = "|56|US Direct|2008|11|MBS Direct|2009|41|Direct|2007
arrPeriod = list.split("|");
var chk = document.getElementsByName
YearArray = new Array();
for (var i=0; i<chk.length; i++)
{
if (chk[i].checked)
{
var YearvalueArray = chk[i].getAttribute("value
YearArray[arrCount] = YearvalueArray[0];
arrCount++;
}
}
arrCount = 0;
for (i=0;i<chk.length;i++)
{
if (arrPeriod[i] == YearArray[0])
{
document.form1.ChkPeriod[i
document.form1.ChkPeriod[i
alert(arrPeriod[i-2]);
alert(arrPeriod[i-1]);
//error it says that the document.form1.ChkPeriod[i
//how can I fix this
}
}
}
</script>
function GetsData()
{
debugger
var YearArray;
var arrCount = 0;
var arrPeriod = new Array();
var list = "|56|US Direct|2008|11|MBS Direct|2009|41|Direct|2007
arrPeriod = list.replace(/^\|/g, '').split("|");
var chk = document.getElementsByName
YearArray = new Array();
for (var i=0; i<chk.length; i++)
{
if (chk[i].checked)
{
var YearvalueArray = chk[i].getAttribute("value
YearArray[arrCount] = YearvalueArray[0];
arrCount++;
}
}
arrCount = 0;
//////////////////////////
// how can I populate the document.form1.ChkPeriod[i
<input id="ChkPeriod" type="checkbox" value="" />
for (i=0;i<chk.length;i++)
{
if (arrPeriod[i] == YearArray[i])
{
document.form1.ChkPeriod[i
document.form1.ChkPeriod[i
alert(arrPeriod[i-2]);
alert(arrPeriod[i-1]);
}
}
//////////////////////////
}
</script>
<form name="form1" id="form1" method="post" >
<table>
<tr>
<td>
<input id="FundYear" type="checkbox" onpropertychange="GetsData
</td>
<td>
<input id="ChkPeriod" type="checkbox" value="" />
</td>
</tr>
</table>
</form>
//////////////////////////
PLEASE NOTE I MADE CHANGES TO THE JAVASCRIPT
<script type="text/javascript">
function GetsData()
{
debugger
var YearArray;
var arrCount = 0;
var arrPeriod = new Array();
var list = "|56|US Direct|2008|11|MBS Direct|2009|41|Direct|2007
arrPeriod = list.replace(/^\|/g, '').split("|");
var chk = document.getElementsByName
YearArray = new Array();
for (var i=0; i<chk.length; i++)
{
if (chk[i].checked)
{
var YearvalueArray = chk[i].getAttribute("value
}
}
for (i=0;i<arrPeriod.length;i++
{
for (e=0;e<YearvalueArray.lengt
{
if (arrPeriod[i] == YearvalueArray[e])
{
document.form1.ChkPeriod.v
document.form1.ChkPeriod.t
alert(arrPeriod[i-2]);
alert(arrPeriod[i-1]);
}
///// THE ONLY PART THAT DOES NOT WORK IS THAT IT DOES NOT POPULATE THE CHKPERIOD CHECKBOX WITH THE VALUE
}
}
}
</script>
>>document.getElementsByName
if you are going to use document.getElementsByName
<input id="FundYear"
so this is likely to give you problems on other browsers. My suggestion: change that to:
<input id="FundYear" name="FundYear"
OR leave it as is and instead of document.getElementsByName
>>///// THE ONLY PART THAT DOES NOT WORK IS THAT IT DOES NOT POPULATE THE CHKPERIOD CHECKBOX WITH THE VALUE
I disagree. A checkbox VALUE is NOT visible on the screen. To test your theory, assign the Value to the "title" attribute of your checkbox. It should give you a tooltip with the value you expect.
>>document.form1.ChkPeriod.t
there is no such property on checkbox. But again, if you were to use:
document.form1.ChkPeriod.t
and then hover over the checkbox you will see the value you seek as a tooltip. If you are trying to put that value next to the checkbox, then you will need some "target" element next to the checkbox and populate that element with the value:
Hielo,
thank you I am very close. I did not include this part because I don't want to complecate you.
I want to tell you that the FundYear checkbox is getting populating from the database with different years. if the user select year 2008 and 2009 it should prompt them with
something like this
if the user select 2008 and 2009
[ ] 2006
[ ] 2007
[ X ] 2008
[ X ] 2009
the user should be prompted with both option
[ ] "US Direct"
[ ] "MBS Direct"
now what's doing is I select 2008 and 2009 it will display "US Direct" only so, it is very close.
<td>
<input id="FundYear" name="FundYear" type="checkbox" onpropertychange="GetsData
</td>
//////////////////////////
<td>
<%
sSQL = "SELECT FIC.ProCode " & _
"FROM dbo.FundControl AS FIC INNER JOIN " & _
"dbo.PnControl AS PC ON FIC.ProCode = PC.ProCode "
set rsFundYr = RunSQL(sSQL, 1)
Do While Not rsFundYr.EOF %>
<input id="FundYear" type="checkbox" onpropertychange="GetsData
<%rsFundYr.MoveNext
Loop %>
</td>
//////////////////////////
Maybe something like this to have multiple checkboxes listed along with the labels.
document.form1.ChkPeriod[i
document.form1.ChkPeriod[i
document.getElementById("l
ChkPeriod[i]
I have to somehow loop and populate the ChkPeriod and lblChkPeriod more than once
right now it over write the lblChkPeriod
>>I want to tell you that the FundYear checkbox is getting populating from the database with different years.
Then you need to start sending UNIQUE ids. You cannot have more than one element with:
id="FundYear"
It is OK to have duplicate/multiple elements with:
name="FundYear"
but NOT ids. If I understand correctly, you seek the functionality below. Notice that all the ids are now unique. All you need to do is to add the appropriate year as a "suffix". Notice that this also apply to the <label> elements. Lastly, you can simply call GetsData(this), instead of the long reference you had previously. Save the attached code as hielo.html and try it:
Business Accounts
Answer for Membership
by: hieloPosted on 2009-11-05 at 10:33:36ID: 25752404
>> if (arrPeriod[2] = YearArray[i])
].value = arrPeriod[0] ].text = arrPeriod[1]
You check for equality with TWO "=" signs. That line should be:
if (arrPeriod[2] == YearArray[i])
Perhaps you meant:
if (arrPeriod[2] == YearArray[i])
{
document.form1.ChkPeriod[i
document.form1.ChkPeriod[i
}