javascript - How to display the background value to the corresponding radio option in html?
我想大声告诉你
我想大声告诉你 2017-05-19 10:43:58
0
2
515
<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?

我想大声告诉你
我想大声告诉你

reply all(2)
仅有的幸福

cObjNo value obtained

滿天的星座

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template