nested arrays and custom objects in javascript
- Cae
- Expert


- Joined: Feb 25, 2004
- Posts: 734
- Status: Offline
ok, im working on this project for school and well, i have no idea what the problem is... its coming up with an 'object expected' error... any suggestions?
Code: [ Select ]
<html>
<head>
<title>Find Student</title>
<script type="text/javascript"></script>
<script>
var year = new Array();
var year[0] = new gradYear();
var year[0].gradYear = 2005;
var year[0].student = new Array();
var year[0].student[0] = new ident();
var year[0].student[0].name = "Schrodinger, Cae";
var year[0].student[0].userName = "schrodingerc";
function gradYear(year, student){
this.year = year;
this.student = student;
}
function ident(name, userName){
this.userName = userName;
this.name = name;
}
function populate(){
alert(year.length);
}
/*
function refreshStudentList(){
var selectedYearIndex = ____ ;
for(var i = 0; i <= (year[selectedYearIndex].student.length() - 1); i++){
studentMenu.options[i] = new Option(year[selectedYearIndex].student[i].name, year[selectedYearIndex].student[i].userName);
}
}
function redirect(){
var targetURL = '/default.asp?student?' + document.findStudent.studentMenu.value;
window.location.href = targetURL;
}
*/
</script>
</head>
<body onload = "populate();">
<center>
<table height ="250" width = "500">
<tr height = "15" valign = "bottom">
<td width = "105">
Graduation Year
</td>
<td>
Student Name
</td>
</tr>
<tr valign = "top">
<form name = "findStudent" action="" method="POST">
<td height="235">
<select name = "yearMenu" size = "10" width = "150" style = "width: 100; height:200" onchange = "refreshStudentList();" onclick="refreshStudentList();">
<option>----------------</option>
</select>
</td>
<td>
<select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
<option>----------------</option>
</select>
</td>
<td>
<input type = "submit" value = "Submit" onclick = "rediredt()">
</td>
</form>
</tr>
</table>
</center>
</body>
</html>
<head>
<title>Find Student</title>
<script type="text/javascript"></script>
<script>
var year = new Array();
var year[0] = new gradYear();
var year[0].gradYear = 2005;
var year[0].student = new Array();
var year[0].student[0] = new ident();
var year[0].student[0].name = "Schrodinger, Cae";
var year[0].student[0].userName = "schrodingerc";
function gradYear(year, student){
this.year = year;
this.student = student;
}
function ident(name, userName){
this.userName = userName;
this.name = name;
}
function populate(){
alert(year.length);
}
/*
function refreshStudentList(){
var selectedYearIndex = ____ ;
for(var i = 0; i <= (year[selectedYearIndex].student.length() - 1); i++){
studentMenu.options[i] = new Option(year[selectedYearIndex].student[i].name, year[selectedYearIndex].student[i].userName);
}
}
function redirect(){
var targetURL = '/default.asp?student?' + document.findStudent.studentMenu.value;
window.location.href = targetURL;
}
*/
</script>
</head>
<body onload = "populate();">
<center>
<table height ="250" width = "500">
<tr height = "15" valign = "bottom">
<td width = "105">
Graduation Year
</td>
<td>
Student Name
</td>
</tr>
<tr valign = "top">
<form name = "findStudent" action="" method="POST">
<td height="235">
<select name = "yearMenu" size = "10" width = "150" style = "width: 100; height:200" onchange = "refreshStudentList();" onclick="refreshStudentList();">
<option>----------------</option>
</select>
</td>
<td>
<select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
<option>----------------</option>
</select>
</td>
<td>
<input type = "submit" value = "Submit" onclick = "rediredt()">
</td>
</form>
</tr>
</table>
</center>
</body>
</html>
- <html>
- <head>
- <title>Find Student</title>
- <script type="text/javascript"></script>
- <script>
- var year = new Array();
- var year[0] = new gradYear();
- var year[0].gradYear = 2005;
- var year[0].student = new Array();
- var year[0].student[0] = new ident();
- var year[0].student[0].name = "Schrodinger, Cae";
- var year[0].student[0].userName = "schrodingerc";
- function gradYear(year, student){
- this.year = year;
- this.student = student;
- }
- function ident(name, userName){
- this.userName = userName;
- this.name = name;
- }
- function populate(){
- alert(year.length);
- }
- /*
- function refreshStudentList(){
- var selectedYearIndex = ____ ;
- for(var i = 0; i <= (year[selectedYearIndex].student.length() - 1); i++){
- studentMenu.options[i] = new Option(year[selectedYearIndex].student[i].name, year[selectedYearIndex].student[i].userName);
- }
- }
- function redirect(){
- var targetURL = '/default.asp?student?' + document.findStudent.studentMenu.value;
- window.location.href = targetURL;
- }
- */
- </script>
- </head>
- <body onload = "populate();">
- <center>
- <table height ="250" width = "500">
- <tr height = "15" valign = "bottom">
- <td width = "105">
- Graduation Year
- </td>
- <td>
- Student Name
- </td>
- </tr>
- <tr valign = "top">
- <form name = "findStudent" action="" method="POST">
- <td height="235">
- <select name = "yearMenu" size = "10" width = "150" style = "width: 100; height:200" onchange = "refreshStudentList();" onclick="refreshStudentList();">
- <option>----------------</option>
- </select>
- </td>
- <td>
- <select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
- <option>----------------</option>
- </select>
- </td>
- <td>
- <input type = "submit" value = "Submit" onclick = "rediredt()">
- </td>
- </form>
- </tr>
- </table>
- </center>
- </body>
- </html>
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 26th, 2004, 12:42 pm
- rtm223
- Mastermind


- Joined: Mar 24, 2004
- Posts: 1855
- Loc: Uk
- Status: Offline
Code: [ Select ]
function gradYear(year, student){
this.year = year;
this.student = student;
}
this.year = year;
this.student = student;
}
- function gradYear(year, student){
- this.year = year;
- this.student = student;
- }
what does this refer to? I only glanced and my js isn't great anymore, but that looks decidedly suspicious?
CSS website design tutorials
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
Don't use var over and over again for the same variable. You only need to declare year once. After that you're just accessing an existing array of objects.
Code: [ Select ]
var year = new Array();
year[0] = new gradYear();
year[0].gradYear = 2005;
year[0].student = new Array();
year[0].student[0] = new ident();
year[0].student[0].name = "Schrodinger, Cae";
year[0].student[0].userName = "schrodingerc";
year[0] = new gradYear();
year[0].gradYear = 2005;
year[0].student = new Array();
year[0].student[0] = new ident();
year[0].student[0].name = "Schrodinger, Cae";
year[0].student[0].userName = "schrodingerc";
- var year = new Array();
- year[0] = new gradYear();
- year[0].gradYear = 2005;
- year[0].student = new Array();
- year[0].student[0] = new ident();
- year[0].student[0].name = "Schrodinger, Cae";
- year[0].student[0].userName = "schrodingerc";
Free Programming Resources
- Cae
- Expert


- Joined: Feb 25, 2004
- Posts: 734
- Status: Offline
- Cae
- Expert


- Joined: Feb 25, 2004
- Posts: 734
- Status: Offline
same project, my menus are working now, however my redirect is not working... it looks fine to me, though i may be missing something... when you click the button it should redirect you yto 'default.asp?student?*value_selected_student*' and i know that it is generating the URL correctly because i have placed alerts in it and its fine... i have also tried it with the whole URL http://server/default.asp... no go... any suggestions?
Code: [ Select ]
<html>
<head>
<title>Find Student</title>
<script type="text/javascript"></script>
<script>
var year = new Array();
year[0] = new gradYear();
year[0].gradYear = "2005";
year[0].student = new Array();
year[0].student[0] = new ident();
year[0].student[0].name = "Schrodinger, Cae";
year[0].student[0].userName = "schrodingerc";
year[0].student[1] = new ident();
year[0].student[1].name = "Name, No";
year[0].student[1].userName = "namen";
year[1] = new gradYear();
year[1].gradYear = "2006";
year[1].student = new Array();
year[1].student[0] = new ident();
year[1].student[0].name = "Wiggen, Ender";
year[1].student[0].userName = "wiggene";
year[2] = new gradYear();
year[2].gradYear = "2007";
year[2].student = new Array();
year[2].student[0] = new ident();
year[2].student[0].name = "Clue, No";
year[2].student[0].userName = "cluen";
function gradYear(gradYear, student){
this.gradYear = gradYear;
this.student = student;
}
function ident(name, userName){
this.name = name;
this.userName = userName;
}
function populate(){
document.findStudent.gradYearMenu.options.length = 0;
for(var i = 0; i <= (year.length - 1); i++){
document.findStudent.gradYearMenu.options[i] = new Option(year[i].gradYear, i);
}
}
function repopulateStudents(){
document.findStudent.studentMenu.options.length = 0;
for(var i = 0; i <= (year[document.findStudent.gradYearMenu.value].student.length - 1); i++){
document.findStudent.studentMenu.options[i] = new Option(year[document.findStudent.gradYearMenu.value].student[i].name, year[document.findStudent.gradYearMenu.value].student[i].userName);
}
}
function redirect(){
window.location.href = '/default.asp?student?' + document.findStudent.studentMenu.value;
}
</script>
</head>
<body onload = "populate();">
<center>
<table height ="250" width = "555">
<tr height = "15" valign = "bottom">
<td width = "110">
Graduation Year
</td>
<td>
Student Name
</td>
</tr>
<tr valign = "top">
<form name = "findStudent" action = "" method = "POST">
<td height = "235">
<select name = "gradYearMenu" size = "10" width = "150" style = "width: 100; height:200" onclick = "repopulateStudents();">
<option>----------------</option>
</select>
</td>
<td>
<select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
<option>----------------</option>
</select>
</td>
<td>
<input type = "submit" value = "Find Student" onclick = "redirect()">
</td>
</form>
</tr>
</table>
</center>
</body>
</html>
<head>
<title>Find Student</title>
<script type="text/javascript"></script>
<script>
var year = new Array();
year[0] = new gradYear();
year[0].gradYear = "2005";
year[0].student = new Array();
year[0].student[0] = new ident();
year[0].student[0].name = "Schrodinger, Cae";
year[0].student[0].userName = "schrodingerc";
year[0].student[1] = new ident();
year[0].student[1].name = "Name, No";
year[0].student[1].userName = "namen";
year[1] = new gradYear();
year[1].gradYear = "2006";
year[1].student = new Array();
year[1].student[0] = new ident();
year[1].student[0].name = "Wiggen, Ender";
year[1].student[0].userName = "wiggene";
year[2] = new gradYear();
year[2].gradYear = "2007";
year[2].student = new Array();
year[2].student[0] = new ident();
year[2].student[0].name = "Clue, No";
year[2].student[0].userName = "cluen";
function gradYear(gradYear, student){
this.gradYear = gradYear;
this.student = student;
}
function ident(name, userName){
this.name = name;
this.userName = userName;
}
function populate(){
document.findStudent.gradYearMenu.options.length = 0;
for(var i = 0; i <= (year.length - 1); i++){
document.findStudent.gradYearMenu.options[i] = new Option(year[i].gradYear, i);
}
}
function repopulateStudents(){
document.findStudent.studentMenu.options.length = 0;
for(var i = 0; i <= (year[document.findStudent.gradYearMenu.value].student.length - 1); i++){
document.findStudent.studentMenu.options[i] = new Option(year[document.findStudent.gradYearMenu.value].student[i].name, year[document.findStudent.gradYearMenu.value].student[i].userName);
}
}
function redirect(){
window.location.href = '/default.asp?student?' + document.findStudent.studentMenu.value;
}
</script>
</head>
<body onload = "populate();">
<center>
<table height ="250" width = "555">
<tr height = "15" valign = "bottom">
<td width = "110">
Graduation Year
</td>
<td>
Student Name
</td>
</tr>
<tr valign = "top">
<form name = "findStudent" action = "" method = "POST">
<td height = "235">
<select name = "gradYearMenu" size = "10" width = "150" style = "width: 100; height:200" onclick = "repopulateStudents();">
<option>----------------</option>
</select>
</td>
<td>
<select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
<option>----------------</option>
</select>
</td>
<td>
<input type = "submit" value = "Find Student" onclick = "redirect()">
</td>
</form>
</tr>
</table>
</center>
</body>
</html>
- <html>
- <head>
- <title>Find Student</title>
- <script type="text/javascript"></script>
- <script>
- var year = new Array();
- year[0] = new gradYear();
- year[0].gradYear = "2005";
- year[0].student = new Array();
- year[0].student[0] = new ident();
- year[0].student[0].name = "Schrodinger, Cae";
- year[0].student[0].userName = "schrodingerc";
- year[0].student[1] = new ident();
- year[0].student[1].name = "Name, No";
- year[0].student[1].userName = "namen";
- year[1] = new gradYear();
- year[1].gradYear = "2006";
- year[1].student = new Array();
- year[1].student[0] = new ident();
- year[1].student[0].name = "Wiggen, Ender";
- year[1].student[0].userName = "wiggene";
- year[2] = new gradYear();
- year[2].gradYear = "2007";
- year[2].student = new Array();
- year[2].student[0] = new ident();
- year[2].student[0].name = "Clue, No";
- year[2].student[0].userName = "cluen";
- function gradYear(gradYear, student){
- this.gradYear = gradYear;
- this.student = student;
- }
- function ident(name, userName){
- this.name = name;
- this.userName = userName;
- }
- function populate(){
- document.findStudent.gradYearMenu.options.length = 0;
- for(var i = 0; i <= (year.length - 1); i++){
- document.findStudent.gradYearMenu.options[i] = new Option(year[i].gradYear, i);
- }
- }
- function repopulateStudents(){
- document.findStudent.studentMenu.options.length = 0;
- for(var i = 0; i <= (year[document.findStudent.gradYearMenu.value].student.length - 1); i++){
- document.findStudent.studentMenu.options[i] = new Option(year[document.findStudent.gradYearMenu.value].student[i].name, year[document.findStudent.gradYearMenu.value].student[i].userName);
- }
- }
- function redirect(){
- window.location.href = '/default.asp?student?' + document.findStudent.studentMenu.value;
- }
- </script>
- </head>
- <body onload = "populate();">
- <center>
- <table height ="250" width = "555">
- <tr height = "15" valign = "bottom">
- <td width = "110">
- Graduation Year
- </td>
- <td>
- Student Name
- </td>
- </tr>
- <tr valign = "top">
- <form name = "findStudent" action = "" method = "POST">
- <td height = "235">
- <select name = "gradYearMenu" size = "10" width = "150" style = "width: 100; height:200" onclick = "repopulateStudents();">
- <option>----------------</option>
- </select>
- </td>
- <td>
- <select name = "studentMenu" size = "10" width = "150" style = "width: 300; height:200">
- <option>----------------</option>
- </select>
- </td>
- <td>
- <input type = "submit" value = "Find Student" onclick = "redirect()">
- </td>
- </form>
- </tr>
- </table>
- </center>
- </body>
- </html>
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
I'm not sure whether you need to use an absolute path for this as I've never tried a relative one, but I'm pretty sure that the second question mark in '/default.asp?student?' should be an equal sign, so that it's
rather than
Code: [ Select ]
http://www.blah.com/page.asp?name=value
rather than
Code: [ Select ]
http://www.blah.com/page.asp?name?value
Free Programming Resources
- Cae
- Expert


- Joined: Feb 25, 2004
- Posts: 734
- Status: Offline
youre thinking PHP... this is ASP...
in ASP you dont assign values to stuff like "page=this&subsection=that"... in ASP its the order that counts... so when it gets the query string it puts it all into an array and you reference it by queryArray(0), queryArray(1) etc... (they should be question marks, its 2 seperate parts of the query string)
the '?student' calling up the student sub-template, and the '?*userName*' is calling up the data for that student... i tried using an absolute path as well as a relitive one ('/default.asp?student?schrodinerc' and 'http://studentserver/default.asp?schrodingerc') they both dont work...
in ASP you dont assign values to stuff like "page=this&subsection=that"... in ASP its the order that counts... so when it gets the query string it puts it all into an array and you reference it by queryArray(0), queryArray(1) etc... (they should be question marks, its 2 seperate parts of the query string)
the '?student' calling up the student sub-template, and the '?*userName*' is calling up the data for that student... i tried using an absolute path as well as a relitive one ('/default.asp?student?schrodinerc' and 'http://studentserver/default.asp?schrodingerc') they both dont work...
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
Sorry, I guess things have changed since I looked at ASP. However, you used to be able to pass values in the same ?name=value manner as in PHP and recover them with request.querystring("name") as I recall. It has been quite awhile though, and I know a lot of things have no doubt changed since asp "classic".
Free Programming Resources
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
Since your using javascript redirection I think you probably don't want the form to submit in the traditional manner because I think it's going to conflict with your attempt to customize the querystring even if you change it to GET since the form will try to send all the fields. When I tried just changing the method to get and still using a submit button Opera did the redirection correctly, but FireFox and IE tried to send all the form fields in the url instead of the customized url from the redirect function. When I left the method as post I got a "page not found" error.
I'd suggest substituting a plain button for a submit button to see if it clears up your problem.
I tried it with the old style using request.querystring to recover the value passed by the redirect function and that was the only way I could get it to work. It may not work with the method of retrieving values that you're using, but it's worth a shot anyway.
I'd suggest substituting a plain button for a submit button to see if it clears up your problem.
Code: [ Select ]
<input type = "button" value = "Find Student" onclick = "redirect()">
I tried it with the old style using request.querystring to recover the value passed by the redirect function and that was the only way I could get it to work. It may not work with the method of retrieving values that you're using, but it's worth a shot anyway.
Free Programming Resources
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 10 posts
- Users browsing this forum: No registered users and 195 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
