SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript error message

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

    Code:
    <!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.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    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.

    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 .

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    (The only thing worse than a missing comment is an incorrect comment.)
    Birnam wood is come to Dunsinane

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    With jQuery you could use the each function:

    Code javascript:
    elem2.each(function() {
        var that = this;
        elem1.each(function () {
            if (this.value === that.value) {
                ...
            }
        });
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •