Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: uncaught exception-->What is this? 1

Status
Not open for further replies.

bigS47

Programmer
Jun 29, 2006
20
CA
I'm making a script and I seem to be getting this error:

Error: uncaught exception: [Exception... "Index or size is negative or greater than the allowed amount" code: "1" nsresult: "0x80530001 (NS_ERROR_DOM_INDEX_SIZE_ERR)" location: "***"]

I have looked on google for an answer, and lots of people seem to be getting this error, but noone seems to know what causes it.

Anybody here have any ideas about it?
 
The error occurs when this function is called upon:

Code:
function addWorkout(value,w){
    var typea=null;
  	typea=new Array();
	
	
  	nullOptions(w,document.getElementById(w+"").getElementsByTagName("select")[1]);
	if(document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled==true) document.getElementById(w+" 1").getElementsByTagName("select")[0].value="";
	if(document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled==true) document.getElementById(w+" 2").getElementsByTagName("input")[0].value="";
	if(document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled==true) document.getElementById(w+" 3").getElementsByTagName("input")[0].value="";
	if(document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled==true) document.getElementById(w+" 4").getElementsByTagName("input")[0].value="";
	if(value=="Recovery Work"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = true;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = true;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[0].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = false;
		typea[0]="Easy endurance work";
	}else if(value=="Base Endurance Work"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = true;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = true;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[0].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = false;
		typea[0]="Prep Endurance";
		typea[1]="Extensive Endurance";
	}else if(value=="Muscular Endurance"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[2].selected=true;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = false;
		typea[0]="Continuous Work";
		typea[1]="Lactate Threshold";
		typea[2]="Lactate Threshold Hills";
		typea[3]="Over Under Workout";
	}else if(value=="Specific Strength"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[6].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = false;
		typea[0]="Roller Ski Strength Workout 1";
		typea[1]="Roller Ski Strength Workout 2 (Single Stick)";
		typea[2]="Roller Ski Strength Workout 3 (Legs Only)";
	}else if(value=="General Strength"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].value="N/A";
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = true;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = true;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[6].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = true;
		typea[0]="Hypertrophy";
		typea[1]="Max strength";
		typea[2]="Endurance Strength";
		typea[3]="Anatomical Adaptation";
		typea[4]="Weightless Workouts";
	}else if(value=="VO2 Max Work"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[5].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = true;
		typea[0]="Ski Walking Leg Power";
		typea[1]="Short Intervals";
		typea[2]="Time Trial";
		typea[3]="Long Pyramid Intervals";
	}else if(value=="Anaerobic Work"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[3].selected=true;
		typea[0]="Small pyramid interval";
		typea[1]="Moving Sprints";
		typea[2]="Uphill Sprints";
		typea[3]="Long Sprints";
	}else if(value=="Speed Skills"){
		document.getElementById(w+" 2").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 3").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("input")[0].disabled = false;
		document.getElementById(w+" 4").getElementsByTagName("select")[0].disabled = false;
		document.getElementById(w+"").getElementsByTagName("select")[1].disabled = false;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].options[4].selected=true;
		document.getElementById(w+" 1").getElementsByTagName("select")[0].disabled = true;
		
		typea[0]="Fast Starts";
		typea[1]="Accelerations";
		typea[2]="Downhill glide";
	}
	k=0;
	while(k<typea.length){
  		document.getElementById(w+"").getElementsByTagName("select")[1].options[k] = new Option(typea[k],typea[k]);
		k=k+1;
	}
	document.getElementById(w+"").getElementsByTagName("select")[1].options[0].selected=true;
}
This functions is called upon in the function above
Code:
function nullOptions(w,menu){
	//superman
	alert(menu.options[menu.selectedIndex].value);
	var tot=menu.options.length;
	for (i=0;i<tot;i++){
		menu.options[i]=null
	}
	menu.options.length=0;
}
 
wow, good times.

do you have a link? this code isn't exactly friendly to read.

what does this do?

Code:
    for (i=0;i<tot;i++){
        menu.options[i]=null
    }
    menu.options.length=0;

you should be able to just do this:

Code:
menu.options.length = 0;

without that loop.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
It doesn't say the error line. (well it just says the line that the javscript starts at, not any line in particular). I really doubt that this is an error with syntax, but I'm pretty sure that it has to do with something with something that the javascript is not able to do or something like that.

As for your previous post, that code is to take all the options off of a drop-down menu to make way for options that will be added in the addWorkout() function.
 
a) you have failed to provide us with any manageable testing harness. the code you provided cannot easily be copied/pasted without rework.

b) having these back-and-forth conversations without providing a link or any specific information makes it hard, if not impossible, to debug your 120+ lines of code with our eyes.

c) as stated in my previous post, your loop is unnecessary - simply setting the length to 0 will do the trick.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Ya it's because I mainly just wanted to know what the error meant, so I could change the code accordingly. I could give you everything, but it is very long, and I doubt anyone would want to go through the whole thing.
 
the error basically means you're trying to reference something out of range.

for example, you might get this error if you have a select box with three options:

Code:
<select name="s">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

but you then try to reference an out-of-bound option:

Code:
document.forms['myFormName'].elements['s'].options[6].selected = true;

since there is no 6th option, this would error out.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
sorry, sometimes i get too into the "give me the code and i'll tell you what's wrong" mode, instead of the "that error means this" mode. most people like to have everything handed to them, rather than understanding the problem and finding the solution on their own.

kudos.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top