JQuery/Ajax: Correct way to write function?

Posted on 2011-10-12
Last Modified: 2012-05-12
Basic Question,

i have a function like this:

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

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:
Thank you.
Question by:boon86
    LVL 1

    Expert Comment

    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.
    LVL 7

    Author Comment

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

    Accepted Solution

    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.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    The viewer will learn how to dynamically set the form action using jQuery.
    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…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now