1

In the following code .tg is a class tag. I get the alert as got here but i d o not see this happen this.html(opt_arr[i]); how to resolve this issue

  function populate_combo()
  {
     var opt_arr=new Array();

     var tg_len = $('.tg').length;
     arr_len = '{{response_dict.opt_arr_len}}';
     if(arr_len == tg_len)
     {
        alert("got here")
        {% for htm in response_dict.opt_arr %}
           opt_arr.push('{{htm}}') 
        {% endfor %}
        $(".tg").each(function (i) {
        this.html(opt_arr[i]);
           });

     }
     else
     {
        alert("There was an error while loadind dropdown box data");
     }

  }

EDIT

   {% for td in response_dict.taggeddata %}
     <tr id="{{td.id}}">
     <td width="20%">{{td.field1}}</td>
      {% if response_dict.tag_flag == 1 %}
              <td class="tg"></td>
     {% endif %}
        </tr>
  {% endfor %}
2
  • +1 for using alert ("got here") Commented Aug 19, 2012 at 17:36
  • What's the value of tg_len? If it's 0 then obviously the each loop will have nothing to do... Commented Aug 19, 2012 at 17:38

2 Answers 2

3

use $(this) instead of this to convert it to jquery object, and use jquery function on it..

$(this).html(opt_arr[i]);

Not Working

Working

Sign up to request clarification or add additional context in comments.

6 Comments

but actually the dropdown box doesnt appear i can see the html code
I presume u are trying to insert options from the for loop..changing html is not the way to do it..
but usually when u say $.html() will sonvert to html right.If not how to go about it in this case
give complete code..what is .tg..do u have select box already..btw u are removing all html of .tg initially..read this..stackoverflow.com/questions/170986/…
I have edited the question and have given the html also have removed $('.tg').html(''); thats not required
|
0
$(".tg").each(function (i, e) {
    e.innerHTML = opt_arr[i];
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.