<form method="post">
roomName : <input type="text" name="roomName" value="<%=room.roomName%>"/><br/>
roomContent:<textarea name="roomContent"><%=room.roomContent%></textarea><br/>
roomCreateUser:<input type="text" value="<%=room.roomCreateUser%>" name="roomCreateUser"/><br/>
roomChat:<input type="radio" name="roomChat" value="public" checked>公聊<input type="radio" name="roomChat" value="secret" >私聊<br/>
<input type="hidden" name="id" value="<%=room._id%>"/>
<input type="submit" value="submit"/>
<input type="reset" value="reset"/>
</form>
<script>
function chatradio(cName,cValue){
var cObj = document.getElementsByName(cName);
for(var i = 0;i < cObj.length;i++){
if(cObj[i].value == cValue){
cObj[i].checked = 'checked';
}
}
};
chatradio('roomchat','<%=room.roomChat%>');
</script>
I want to check the roomChat value that already exists in the background to the corresponding value on the html page, and then display it on the corresponding option of the html page. I found the above method on the Internet and changed it myself into the above code. But what else went wrong, causing the background value to still not be checked correctly?
滿天的星座2017-05-19 10:45:58
Each group of radios must be in a container. You can define an id for each container. For example, if each group of containers is placed in a p, you can define the id for the first container as id1