onchange show new fields and validate


I’ve a situation here. I’m building an enrolment form for a student app. When you select a particular course(Let’s days course id 18,9) it will show ask another question whether you’ve prerequisite course. In the form, I’ve dynamically create two divs with same field name but different div id ie course18 and course9. Validation works for course id 9 but not 18. It submit empty values. But works for course id 9. Looks like last div’s form validation work.

Here is my form

<div id=course18 class=hide>

<input type="radio" name="prerequisite">


<div id=course9 class=hide>

<input type="radio" name="prerequisite>


using javascirpt onchange I show hide divs. Let’s say if you select course 18 then only course18 div will visible do the validation

When I select course9 and hit submit prerequisite it sends prerequisite field empty

Any help would be great…