micah1701 Posted March 1, 2007 Share Posted March 1, 2007 This works in FireFox but not IE7 (haven't tested in IE6) There are two radio buttons and a textfield. If the user enters a value in the text box, it should check one radio button (with the id="choice") and uncheck the other. If the value in the textfield is zero or blank, it checks the id="choiceNone" radio button and unchecks the other. <script type="text/javaScript"> function checkDonation(id){ var amount = document.getElementById('donationAmount').value; var zeroField = id+"None"; //var should be equal to "choiceNone" if (amount > 0){ document.getElementById(id).checked = true; document.getElementById(zeroField).checked = false; }else{ document.getElementById(zeroField).checked = true; document.getElementById(id).checked = false; } } </script> <input name="choice" type="radio" id="choiceNone"> <input name="choice" type="radio" id="choice" > <input name="donationAmount" type="text" id="donationAmount" onkeyup="checkDonation('choice')" /> and ideas what i'm doing wrong?!! I'm used to having CSS problems in IE but javaScript problems in one browser and not the other are new to me. What am I missing? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 Not sure, looks fine to me.. are you sure you're getting into the correct control paths? Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 1, 2007 Author Share Posted March 1, 2007 i've tested enough to make sure the script is calling the right getElementById()'s even manually creating static vars (instead of passing values to the function). not sure what else you might mean by "control paths" for testing, I added the following line at the end of the function: alert(id+": "+document.getElementById(id).checked+"\n"+zeroField+": "+document.getElementById(zeroField).checked) When you enter a value in the textfield... in FireFox you get choice: true choiceNone: false but in IE you get choice: false choiceNone: false weird? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 I mean getting into the if path vs the else path. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 1, 2007 Author Share Posted March 1, 2007 oh right. yeah, i've tested for that as well, with alerts like: if (amount > 0){ document.getElementById(id).checked = true; document.getElementById(zeroField).checked = false; alert("you have entered an amount greater then zero"); }else{ document.getElementById(zeroField).checked = true; document.getElementById(id).checked = false; alert("you have entered 0 or less, or entered nothing"); } ...and i get the correct responses. so still not sure what the deal is. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 Me neither... don't have IE at work, I'll look at it when I get a chance. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 1, 2007 Author Share Posted March 1, 2007 thanks for your help thus far Fenway. If anyone else would like to take a crack in the meantime, please give it a whirl! This is starting to drive me nuts! Quote Link to comment Share on other sites More sharing options...
nogray Posted March 1, 2007 Share Posted March 1, 2007 You just used a reserved word as the id 'choice' change it to something else and it should work, like this <script type="text/javaScript"> function checkDonation(id){ var amount = document.getElementById('donationAmount').value; var zeroField = id+"None"; //var should be equal to "choiceNone" if (amount > 0){ document.getElementById(id).checked = true; document.getElementById(zeroField).checked = false; }else{ document.getElementById(zeroField).checked = true; document.getElementById(id).checked = false; } } </script> <input name="choice" type="radio" id="chsNone"> <input name="choice" type="radio" id="chs" > <input name="donationAmount" type="text" id="donationAmount" onkeyup="checkDonation('chs')" /> Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 2, 2007 Author Share Posted March 2, 2007 You just used a reserved word as the id 'choice' That was it! Thank you so much. I didn't realize it was a reserved word. go figure. Thank again, i'll be able to sleep tonight. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 2, 2007 Author Share Posted March 2, 2007 UPDATE: You were only partially right. I don't think "choice" is a reserved word - but either way, turns out that is irrelevant to my problem. my problem was that one of my inputs had an ID that was the same as the NAME for both inputs. Turns out that IE is stupid and getElementById('id') really returns what would be the getElementsByName('name') object. go figure. there quite a bit on this subject out there on google Quote Link to comment Share on other sites More sharing options...
fenway Posted March 2, 2007 Share Posted March 2, 2007 UPDATE: You were only partially right. I don't think "choice" is a reserved word - but either way, turns out that is irrelevant to my problem. my problem was that one of my inputs had an ID that was the same as the NAME for both inputs. Turns out that IE is stupid and getElementById('id') really returns what would be the getElementsByName('name') object. go figure. there quite a bit on this subject out there on google No kidding... granted, I never put IDs for tags that can have NAMEs... maybe that's why. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.