I have the following code snippets. Basically what I'm trying to do is a 1st click function through which I look at the JSON cache data and display any values ββthat exist for this identifier. In the second function of the change, I write down when one of the elements changes the values ββ(i.e., Yes to no, and vice versa).
All of these elements are generated dynamically, although the JSON data that I get from the web service. In my opinion, therefore I should use .live functionality.
In Firefox, everything works as expected (of course). However, in IE7 this is not the case. In IE7, if I select a switch that displays a warning from a click function, it also adds the changed function to the array. However, if the switch does nothing of the click function, then an array is not added for the change.
Since I look at this code, I think I could combine these 2 functions together, but for now I just want it to work in IE7.
$(document).ready(function () { //This function is run whenever a 'radio button' is selected. //It then goes into the CPItemMetaInfoList in the cached JSON data //($.myglobals) and checks to see if there are currently any //scripts to display. $("input:radio").live("click", function () { var index = parseInt(this.name.split(':')[0]); for (i = 0; i <= $.myglobals.result.length - 1; i++) { if ($.myglobals.result[i].CPItemMetaInfoList.length > 0) { for (j = 0; j <= $.myglobals.result[i].CPItemMetaInfoList.length - 1; j++) { if (index == $.myglobals.result[i].QuestionId) { alert($.myglobals.result[i].CPItemMetaInfoList[j].KeyStringValue); return; } } } } }); }); $(document).ready(function () { var blnCheck = false; //Checks to see if values have changed. //If a value has been changed then the isDirty array gets populated. //This array is used when the questionSubmit button is clickeds $('input').live('change', function () { blnCheck = false; for (i = 0; i <= isDirty.length - 1; i++) { if (isDirty[i] == $(this).attr("name")) { blnCheck = true; break } } if (blnCheck == false) { isDirty[arrayCount] = $(this).attr("name"); arrayCount += 1; alert($(this).attr("name")); } }); $('textarea').live('change', function () { blnCheck = false; for (i = 0; i <= isDirty.length - 1; i++) { if (isDirty[i] == $(this).attr("id")) { blnCheck = true; break } } if (blnCheck == false) { isDirty[arrayCount] = $(this).attr("id"); arrayCount += 1; //alert($(this).attr("name")); } }); });
UPDATE:
I had to move this piece of code into a click function:
blnCheck = false; for (i = 0; i <= isDirty.length - 1; i++) { if (isDirty[i] == $(this).attr("name")) { blnCheck = true; break } } if (blnCheck == false) { isDirty[arrayCount] = $(this).attr("name"); arrayCount += 1; alert($(this).attr("name")); }
Like this:
$(document).ready(function () { //This function is run whenever a 'radio button' is selected. //It then goes into the CPItemMetaInfoList in the cached JSON data //($.myglobals) and checks to see if there are currently any //scripts to display. $("input:radio").live("click", function () { var index = parseInt(this.name.split(':')[0]); for (i = 0; i <= $.myglobals.result.length - 1; i++) { if ($.myglobals.result[i].CPItemMetaInfoList.length > 0) { for (j = 0; j <= $.myglobals.result[i].CPItemMetaInfoList.length - 1; j++) { if (index == $.myglobals.result[i].QuestionId) { alert($.myglobals.result[i].CPItemMetaInfoList[j].KeyStringValue); return; } } } } blnCheck = false; for (i = 0; i <= isDirty.length - 1; i++) { if (isDirty[i] == $(this).attr("name")) { blnCheck = true; break } } if (blnCheck == false) { isDirty[arrayCount] = $(this).attr("name"); arrayCount += 1; } }); });
But...
I had to leave the change function the same. From my testing, I found that the .click function worked for IE7 for radio buttons and checkbox elements, but the .change functionality worked for text fields and text fields in IE7 and FF, as well as the original radio button and checkbox functions.
It became a real mess. Thanks @Patricia for this. Here the suggestions led me to this decision. I am going to leave the question unanswered, as I am wondering if there is a cleaner solution in it.