I am trying to show/hide an element with raw Javascript when a radio button has a specific value. I can get it to work with inline Javascript, but I want to try and do it using the addEventListener method.
Here is my HTML:
<label for="petType">Type of Pet: </label>Cat<input" class="radio" name="petType" type="radio" id="petType" value="cat">Dog<input class="radio" name="petType" id="petType" type="radio" value="dog">Other<input class="radio" name="petType" id="petType" type="radio" value="other">
<label for="state">Breed:</label>
<select id="breed">
<option>Shiba Inus</option>
<option>Pembroke Welsh Corgi</option>
<option>Boxer</option>
<option>English Bulldog</option>
</select>
Here is the Javascript I am using to get it to run while using the inline function, with the handler onchange="asdf(this.value)" in my HTML.
function asdf(x) {
var breed = document.getElementById('breed');
if (dog == "dog") {
breed.style.display = "inline";
}
else {
breed.style.display = "none";
}
}
Here is what I have so far:
function asdf(x) {
var breed = document.getElementById('breed');
if (dog == "dog") {
breed.style.display = "inline";
}
else {
breed.style.display = "none";
}
}
var typeOfPet = getElementsByName('petType');
typeOfPet.addEventListener('change', asdf, false);
Fiddle: http://jsfiddle.net/ePDx9/