1

I have several checkbox with different Id's. and a text area named taSignOff. The trigger is invoked once checkbox is ticked / checked. Was wondering why this code is not working in Chrome or IE? In firefox, it runs smoothly.

Here's the code.

var selectedvalue=[];
function checkTickArea(id)
       {
           $('#'+id).change(function () {
               //If checked then push the value
               if( $('#'+id).is(":checked"))
               {
                   selectedvalue.push($('#'+id).attr("value"));
               }else
               {
                   //This is what pops the value from the array when the checkbox is unchecked.
                 /*  var index = selectedvalue.indexOf($('#'+id).attr("value"));
                   if (index > -1) {
                       selectedvalue.splice(index, 1);
                   }*/
                   selectedvalue.splice(selectedvalue.indexOf($(this).attr("value")),1);
               }
               document.getElementById('taSignOff').value = selectedvalue.join("->\n");
           });
       }
k3vin023
  • 15
  • 1
  • 7
  • What does "not working" mean? How is the function invoked? If it's invoked more than once with the same id, you'll be rebinding the same handler multiple times. – cookie monster Dec 16 '13 at 01:48
  • @cookiemonster when u tick the checkbox, the value doesn't go to the taSignOff.. – k3vin023 Dec 16 '13 at 01:51
  • 1
    indexOf is not supported by IE8 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Browser_compatibility – L105 Dec 16 '13 at 01:54
  • @L105 so what will be the alternative for indexOf()? – k3vin023 Dec 16 '13 at 01:55
  • Create your own if not available http://stackoverflow.com/questions/3629183/why-doesnt-indexof-work-on-an-array-ie8 OR use inArray from jQuery http://api.jquery.com/jQuery.inArray/ – L105 Dec 16 '13 at 01:56

0 Answers0