chris cozzens chris cozzens - 12 days ago 6
HTML Question

Getting Form Values returns undefined in IE only

I am pulling my hair out. I have a form on my webpage and some javascript that is pulling the values from the form and I am taking various actions based on the input.

When troubleshooting, The value is being returned as undefined.

JS

var days = document.forms["meal-radio"].elements["days"].value;


HTML

<form class= "meal-table" id="meal-radio" onsubmit="return false">
<div class ="meal-plan-choice row" id="Meals4">
...................................................................
<fieldset id="days">
<div class="width40">
<input type="radio" id="radio08" name="days" value="Five"/>
<label for="radio08"><span class="radiospan"></span>5 Days</label>
</div>


<div class="width40">
<input type="radio" id="radio09" name="days" value="Seven"/>
<label for="radio09"><span class="radiospan"></span>7 Days</label>
</div>

</fieldset> <!-- end style fieldset-->
..............................................................
</div></form>


This is not working only in IE, works fine in Chrome and Firefox

Answer

Being that you tagged in your question, I'm going to assume you're willing to accept jQuery answers.

You could use this, which works in all browsers:

var days = $("#days input[type='radio']:checked").val()
Comments