locked
Unable to check Radio button through Javascript in IE RRS feed

  • Question

  • User987907039 posted

    I am trying to dynamically set a radio button on a web-page through javascript depending on the id of a button.

    Code is the following:

    if ('@Model.Detail.WorkType' != 'Work') {
                    if ('@Model.Detail.EventType' == 'Come' && '@Model.Detail.WorkType' == 'ActiveTravel') {
                        document.getElementById('ActiveTravelTimeComeRadio').checked = true;
                    } else if ('@Model.Detail.EventType' == 'Come' && '@Model.Detail.WorkType' == 'PassiveTravel') {
                        document.getElementById('PassiveTravelTimeComeRadio').checked = true;
                    } else if ('@Model.Detail.EventType' == 'Leave' && '@Model.Detail.WorkType' == 'ActiveTravel') {
                        document.getElementById('ActiveTravelTimeLeaveRadio').checked = true;
                    } else {
                        document.getElementById('PassiveTravelTimeLeaveRadio').checked = true;
                    }
                } else if ('@Model.Detail.WorkType' == 'Work') {
                    if ('@Model.Detail.EventType' == 'Come') {
                        document.getElementById('ComeRadio').checked = true;
                    } else {
                        document.getElementById('LeaveRadio').checked = true;
                    }
                }

    This does work in google chrome, but it doesn't work in IE or Microsoft Edge. How do I make it work in IE and other browsers?

    Tuesday, September 17, 2019 6:21 AM

All replies

  • User-719153870 posted

    Hi Sinner3107,

    This does work in google chrome, but it doesn't work in IE or Microsoft Edge. How do I make it work in IE and other browsers?

    According to your description, seems that you think the document.getElementById('ActiveTravelTimeLeaveRadio').checked = true; can't work in both IE and Edge, right?

    However, i built a simple demo and tested in these three browser and they all wet well. Please take a look at this demo:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
            function check() {
                document.getElementById('ActiveTravelTimeComeRadio').checked = true;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:RadioButton ID="ActiveTravelTimeComeRadio" runat="server" />
                <input type="button" id="btn" value="Check" onclick="check()" />
            </div>
        </form>
    </body>
    </html>

    And the result of this demo in IE ,Edge and Chrome:

    Thus, i recommend you should use the F12 in IE or Edge when you fire the event to check if the event was fired and if it's fired successfully fired, check if the document.getElementById('ActiveTravelTimeComeRadio').checked = true; or the other similar code is excuted. Or, is there any error message in console.

    Since the code provided is limited, you will need to do the trouble shooting by yourself.

    Best Regard,

    Yang Shen

    Tuesday, September 17, 2019 7:36 AM
  • User-474980206 posted
    Also as the logic is all based on server render values, not sure why the server doesn’t do it. Why JavaScript?
    Thursday, September 19, 2019 2:13 PM