Skip to content Skip to sidebar Skip to footer

Including Listitem Variables In Javascript Function Call

I have a nested ListView (Master/Detail) and want to invoke a JavaScript function in the detail ItemTemplate so that this function can call a static method on the server site and p

Solution 1:

It doesn't work because your auto generated id is "ctl00_body_lstQuestions_ctrl0_lstAnswers_ctrl0_txtAnswer" Which is Garbage + txtAnswer.

There are two ways to deal with it, either you think of something clever or use jQuery

var textBox = $("[id$='txtAnswer']");

The easiest way to handle this is a little script tag

<script>var textBox = document.getElementById("txtAnswer");
   if (document.attachEvent) {
        document.attachEvent("onblur", textBox, function() {
             SaveAnswer(
                 '<%#Eval("ThisPAQID")%>', 
                 '<%#Eval("QuestionID")%>', 
                 window.event.target.value
             );
        });
   } else {
       document.addEventListener("blur", textBox, function() {
           SaveAnswer(
               '<%#Eval("ThisPAQID")%>', 
               '<%#Eval("QuestionID")%>', 
               this.value
           );
       }, false);
   }
</script>

Post a Comment for "Including Listitem Variables In Javascript Function Call"