0

I have a VS2010,C# ASP.NET web app, I've written a JavaScript (in aspx page) that works perfect in firefox but almost does nothing in chrome or IE, it is my function:

       <script type="text/javascript" >
       function onRadioChange(rowIndex, value, myHref) {
           var q = document.getElementById('HF').value.toString();
           var q2 = q.split(',');

           var new_HF = '';

           for (var i = 0; i < rowIndex; i++) {
               new_HF += q2[i] + ',';
           }

           new_HF += value.toString() + ',';

           for (var j = rowIndex; j < q2.length - 1; j++) {
               if (j > rowIndex) {
                   new_HF += q2[j] + ',';
               }
           }

           document.getElementById('HF').value = new_HF;

           //user has voted all questions? enable hpAccept so that he can go to next questionnaire
           var q5 = new_HF.split(',');
           var all_ok = true;
           for (var g = 0; g < q5.length; g++) {
               if (q5[g] == '0')
                   all_ok = false;
           }
           if (all_ok) {
               document.getElementById('hpAccept').disabled = false;
               document.getElementById('hpAccept').href = myHref;
           }
       }

it seems that this function does nothing in IE or chrome, I placed and alert to display some info but nothing was displayed in chrome or IE, what is wrong with them?

another problem is on the last parts, the hyperlink is initially disabled, but it is enabled in firefox no luck in IE or chrome, what is the problem here? how can I make this function cross-browser?

[EDIT] I put an alert('1') exactly after function definition line and I saw nothing in chrome and IE, it seems that this function is not called in these browsers, I use r.Attributes.Add("onChange", "return onRadioChange('" + (i - 1).ToString() + "','1','" + myHref + "');"); for calling this function in codebehind, r is a dynamically created radiobutton.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Ali_dotNet
  • 3,219
  • 10
  • 64
  • 115
  • 2
    Did you check the console for errors? In Chrome: Right Click anywhere -> Inspect Element -> Console – Aaron Digulla Jan 12 '12 at 12:34
  • try something like `removeAttribute('disabled');` – greut Jan 12 '12 at 12:38
  • it seems that it gets some error before all_ok, where should I use removeattribute? – Ali_dotNet Jan 12 '12 at 12:39
  • I put an alert('1') exactly after function definition line and I saw nothing in chrome and IE, it seems that this function is not called in these browsers, I use r.Attributes.Add("onChange", "return onRadioChange('" + (i - 1).ToString() + "','1','" + myHref + "');"); for calling this function in codebehind, r is a dynamically created radiobutton – Ali_dotNet Jan 12 '12 at 12:43
  • What is the error that you get in the console? – sebastianf182 Jan 12 '12 at 12:47
  • how can I view console errors? where is it in IE or chrome? – Ali_dotNet Jan 12 '12 at 12:52
  • See the first comment or here: http://code.google.com/chrome/devtools/docs/console.html – Aaron Digulla Jan 13 '12 at 13:32
  • possible duplicate of [Radio Button change event not working in chrome or safari](http://stackoverflow.com/questions/5090560/radio-button-change-event-not-working-in-chrome-or-safari) – jrummell Jan 13 '12 at 13:35

2 Answers2

1

You are not supposed to disable the a tag.

The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.

Source: http://www.w3.org/TR/html4/interact/forms.html#adef-disabled

That´s why document.getElementById('myLink').disabled returns undefined.

Stefan
  • 5,644
  • 4
  • 24
  • 31
  • thanks, how should I change my function? as I said it seems that this function is not called at all, even the upper parts of the function do nothing in IE (8) and chrome, is there any problem with calling the function from codebehind:r.Attributes.Add("onChange", "return onRadioChange('" + (i - 1).ToString() + "','1','" + myHref + "');"); – Ali_dotNet Jan 12 '12 at 13:22
  • Could you view the HTML source of you page and include it in your question? Need the parts with your rendered "r" control. – Stefan Jan 12 '12 at 13:26
1

Duplicate of Radio Button change event not working in chrome or safari

Solution: For Radiobuttons, use the onClick event instead of onChanged

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820