html5 - How to set an HTML radio button using a JavaScript array variable -


i have

<label for="gender" class="housedata">male</label> <input type="radio" id="housegender" name="gender" class="housedata" value="male"/> <label for="gender" class="housedata">female</label> <input type="radio" id="housegender" name="gender" class="housedata" value="female"/> 

and

document.getelementbyid("housegender").value = house[houseid] [7]; 

where house[houseid] [7]; either male or female.

when above assignment, radio button gender unchanged.

any ideas how fix appreciated!

:-)

the id attribute of element must unique. have more 1 element id of housegender.

you need provide unique ids 2 elements (say, housegendermale , housegenderfemale). check value want assign, pick right element, , set checked property true. example:

document.getelementbyid("housegendermale").checked = 'true'; 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -