Hide/Show div via Radio Buttons
I'm trying to hide or show a div based on the value of some radio buttons, css defaults the div to display='none'
Here's the input
<input type="radio" id="payment_type" value="cash" checked="checked" name="payment_type" onchange="showhideFinancing(this.value);"/> Cash/Debit
<input type="radio" id="payment_type" value="cheque" name="payment_type" onc开发者_JAVA技巧hange="showhideFinancing(this.value);"/> Cheque
<input type="radio" id="payment_type" value="visa" checked="checked" name="payment_type" onchange="showhideFinancing(this.value);"/> VISA
<input type="radio" id="payment_type" value="mc" name="payment_type" onchange="showhideFinancing(this.value);"/> Mastercard
<input type="radio" id="payment_type" value="financing" name="payment_type" onchange="showhideFinancing(this.value);"/> Financing
Here's the div:
<div id="financing">
...
</div>
My Javascript fn looks like this:
function showhideFinancing(payment_type) {
if (payment_type == "financing") {
document.getElementById("financing").style.display = 'block';
} else {
document.getElementById("financing").style.display = 'none';
}
}
Firebug shows that getElementById is not defined--Thanks!
The only reasons I can think that it might be saying "getElementById" is not defined is if either you made a typo in your original code that you didn't while putting the sample up here (case sensitive is always the one that gets me) or if you have somehow redefined document elsewhere in the page.
Hmmm are you sure you got the IDs right? Check for duplicates. It's hard to tell without seeing the actual code.
Everything seems solid here. If you're getting a getElementById() is not defined then it will probably be either a typo or some missing syntax like mismatched brackets. You can assume that your html is right for now, focus on the script tag or file where the function is defined I'm pretty sure your problem lies in there.
Post more of that code to get more help.
The code you have there, line for line, works for me in Safari. getElementByID is like part of the root implementation of the DOM; if its not defined I think you have problems with Firefox.
http://firefiter.com/temp.php
精彩评论