Javascript error message

I’m gettting syntax error in this javascript . Could you please help



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <script type="text/javascript" src="jquery-1.4.2.min.js"> </script>
 <script type="text/javascript">
$(document).ready(function(){


var elem1= $(".class1");  //All elements with class="class2"

var elem2 = $(".class2");  //All elements with class="class1"

var elem3= $(".class3");  //All elements with class="class3"

var elem4= $(".class4");  //All elements with class="class4"

var elem5= $(".class5");  //All elements with class="class4"


for(var i = 0; i < elem2.length; i++) {
        
	for(var j = 0; j < elem1.length; j++) {
		
        var terrId1 =  elem2[i].value;
		 var terrId2 =  elem1[j].value;
		if((terrId1 == terrId2)){
		   var hdnclsfname = elem3[j].value;
			var clsfname =  elem5[i].value;
			alert('hi');
			 if((hdnclsfname == clsfname)){
			  alert('hello');
				 if((elem4[i].value =='8')){

				 alert('found');
			  

		      }
		   }
  }
}
});
 
</script>
</HEAD>

 <BODY>
  
   all code removed

 </BODY>
</HTML>


error message:

Line 46
Char 2
Code 0
Syntax error.

That works fine. great …that was beautiful.

Do you have any suggestion to improve this code . As you see I am using two for loops to find a match .

Is there any JQuery in-built function which could make this logic faster ?

Alternatively, what I am asking is , Is there any opportunity to make this code much smart and faster with the help of JQuery ? I’m a JQuery novice user .

With jQuery you could use the each function:


elem2.each(function() {
    var that = this;
    elem1.each(function () {
        if (this.value === that.value) {
            ...
        }
    });
});

I can’t help you there, I’m afraid. I don’t use jQuery (or similar, bloated libraries).

BTW, you really should fix those comments or you’ll confuse the heck out of yourself six months down the line. :slight_smile:
(The only thing worse than a missing comment is an incorrect comment.)

Your ‘}’ tokens don’t match up with your ‘{’ tokens.
You need to add another ‘}’ after the last one.

It’s a bit hard to spot with the wildly inconsistent indention, though. :eek: