Reputation: 27
I'm using an array to add data to my database, and JavaScript to show and hide field depending on yes and no.
<input type="radio" id="medication1" name="medication[]" value="Yes" />
<input type="radio" id="medication2" name="medication[]" value="No" />
$("#show").hide();
$("input[name=medication]").click(function()
{
if ($("#medication1").attr('checked'))
$("#show2").hide();
if ($("#medication2").attr('checked'))
$("#show2").show();
});
Without the array block quotes it works perfectly but once I add them it doesn't. Is there maybe a way I can get around this?
Upvotes: 0
Views: 45
Reputation: 35973
try this with ^=
in your selector you tell to select all input with name that start with medication
$("#show").hide();
$("input[name^=medication]").click(function()
{
if ($("#medication1").attr('checked'))
$("#show2").hide();
if ($("#medication2").attr('checked'))
$("#show2").show();
});
Upvotes: 1
Reputation: 100195
change
$("input[name=medication]").click(function()
to
$("input[name='medication[]']").click(function()
Upvotes: 0