0

I am new to JavaScript so sorry if this is a dumb question!

I am making a web app using Flask that writes school reports. One of the inputs that user selects is the child's gender and this assigns pronouns to variables.They use a radio button to select the gender.

However, my problem is that the 'if' statement is always returned. The code runs, but it always includes the information from this statement.

Any help would be really appreciated!

if else statement

html radio buttons

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • also note that, "Id is unique in a page and can only apply to at most one element" whereas "The class can be applied to multiple elements so it could be multiple times on a single page". – Santa Jul 05 '20 at 05:41

2 Answers2

1

Haha, the problem is that the two radio shares the same id gender.

So when you getElementById('gender'), the machine won't know which do you really want!

user26742873
  • 919
  • 6
  • 21
0

First of all in radio buttons you must use a id at input and a for in label with the same value of id, in your example :

<p> Please select child's gender : <p>
<input type="radio" id="male" name="gender" value="girl">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="girl">
<label for="female">female</label>

if you want help for javascript if statement please share your javascript code