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!

Rogue semicolon causing js error in IE5.5 with dynamic selects

Status
Not open for further replies.

tanny

Programmer
Jan 28, 2001
15
AE
Hi,

This is the code (in its entirety) that I'm running
Code:
function tdarray(texttext, valuetext){
	this.texttext = texttext;
	this.valuetext = valuetext
	}
function ChangetdTo(strpfid){
var copyofarray;
var tdtypes=new Array(tdarray);
for (i=0;i < document.setfilters.td.length - 1;i++){
 tdtypes[i] = new tdarray(document.setfilters.td[i].text, document.setfilters.td[i].value)
}
copyofarray = tdtypes;
var j=0;
for (i = 0; i<tdtypes.length; i++) {
	var comparestring = tdtypes[i].valuetext.substr(0,2);
if (strpfid == comparestring) {
Code:
   		var option + j = new Option(tdtypes[i].texttext, tdtypes[i].valuetext);
		j = j+1;
		} 
	}
	for (i=0; i<j; i++) {
	eval(&quot;inForm.td.options[i]=option&quot; + i)
		}
   history.go(0)
}

I keep getting told that it's expecting ';' on the line saying:

if (strpfid == comparestring) {

Any ideas anybody?
 
I think you are confusing it because you are using semicolons in some places, but not in others.

Third line is missing one --
First for loop is missing one on the action of the loop--
Last for loop is missing one on the action of the loop --
History.go is also missing one--

You know you don't have to use them in javascript, right? But if you do start using them, then you should be more consistent in their use.

good luck:)
Paul Prewett
 
Hi Paul,

Thanks for your post. I put semicolons against all of the statements, but no luck. Still falls over at that same line with the same error message.

Have even tried taking all of the semicolons off, but same message comes up.

What is it with Javascript and semicolons! :))

Tania
 
Fix...

Hi all. Just an update to this. The compiler always shows the error as on the line above the line where there is a real error. So the culprit in this case was the line declaring var option + j etc etc.

I rewrote the script to make sure I only declared a variable once and it worked. Here is the final code:

Code:
function ChangetdTo(){
var strpfid = document.forms(0).pfid.options[document.forms(0).pfid.options.selectedIndex].value
var j=0
document.forms(0).td.length = 0
if (strpfid==&quot;&quot; ){
	for (i=0;i<tdtypes.length;i++) {
		eval(&quot;document.forms(0).td.options[i]=new Option('&quot; + tdtypes[i].texttext + &quot;','&quot; + tdtypes[i].valuetext + &quot;')&quot;)
		}
	}
else {
	for (i = 0; i<tdtypes.length; i++) {
		var comparestring = tdtypes[i].valuetext.substr(0,2)
		if (strpfid == comparestring) { 
			eval(&quot;document.forms(0).td.options[j]=new Option('&quot; + tdtypes[i].texttext + &quot;','&quot; + tdtypes[i].valuetext + &quot;')&quot; )
			j = j+1
			} 
		}
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top