?
Solved

JQuery/Ajax: Correct way to write function?

Posted on 2011-10-12
4
Medium Priority
?
262 Views
Last Modified: 2012-05-12
Basic Question,

i have a function like this:

<script language="javascript" type="text/javascript">  
$(function(){
  $("select#kum_data").change(  
  function(){
    $.getJSON("getdata.jsp",{kum_data: $(this).val(), ajax: 'true1'}, 
    function(j){
      var options1 = '';
      for (var i = 0; i < j.length; i++) {
        options1 += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
      }
      $("select#kategori").html(options1);
    })
  })
  
  $("select#kategori").change(  
  function(){
    $.getJSON("getdata.jsp",{kategori_data: $(this).val(), ajax: 'true2'}, 
    function(k){
      var options2 = '';
      for (var o = 0; o < k.length; o++) {
        options2 += '<option value="' + k[o].optionValue + '">' + k[o].optionDisplay + '</option>';
      }
      $("select#pekara").html(options2);
    })
  })
  
  $("select#pekara").change(  
  function(){
    $.getJSON("getdata.jsp",{isu_data: $(this).val(), kategori_data: $("select#kategori").val(),  ajax: 'true3'}, 
    function(l){
      var options3 = '';
      for (var p = 0; p < l.length; p++) {
        options3 += '<option value="' + l[p].optionValue + '">' + l[p].optionDisplay + '</option>';
      }
      $("select#data").html(options3);
    })
  }) 
})
</script>

Open in new window


Its able to work and get and submit data without problem, question is inside my jdev i saw different color(red) on < k.length; o++) { onward, i feel something is wrong with the code.

Anyone could tell me what is the correct way to correct code above so that i dont get red color?

check Screenshot for more detail:
 screenshot
Thank you.
0
Comment
Question by:boon86
  • 2
3 Comments
 
LVL 1

Expert Comment

by:mc10
ID: 36958600
It's likely just a bug with the IDE. Cut (Ctrl-X) the relevant parts of the code, then re-paste it. Syntax-highlight for that part of the code should be fixed.
0
 
LVL 7

Author Comment

by:boon86
ID: 36958624
thanks for reply i tried it still same. you have any idea? if no, just leave it as long as the code is working
0
 
LVL 1

Accepted Solution

by:
mc10 earned 2000 total points
ID: 36958631
Try re-typing just the for loop; maybe that will fix the syntax highlighting. If that doesn't work, I wouldn't stress too much about it; if the code is working, it should be fine.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question