Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to Check On RadioButtonList, if YEs then textbox is enable and if radiobuttonlist is no then textbox is disable.. i tried but after check and un-check then my web form is refreshing that i don't want
Posted

This may help you....


XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Hide OR Show DIV</title>
    <style type="text/css">
        .box
        {
            display: block;
            border-radius: 8px;
            height: 150px;
            width: 300px;
            border: 2px solid lightgray;
            margin: 0 auto;
            padding: 3px;
            position: fixed;
            cursor: move;
        }
    </style>

    <script type="text/javascript">

        function hideorshow(s) {
            debugger;
            if (s == 'Show') {
                //            var rdbs = document.getElementById("rdbShow").checked;
                //            var rdbh = document.getElementById("rdbHide").checked;

                //            if (rdbs == true) {
                document.getElementById('d1').style.display = "block";
                document.getElementById('rdbHide').checked = false;
            }
            if (s == 'Hide') {
                document.getElementById('d1').style.display = "none";
                document.getElementById('rdbShow').checked = false;
            }
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <p>
            <input type="radio" onclick="hideorshow('Show');" id="rdbShow" value="Show" />
            <input type="radio" onclick="hideorshow('Hide');" id="rdbHide" value="Hide" />
            <div align="center" style="display: none;" class="box" id="d1">
                <h1>
                    Hello, Wel Come To Code Project</h1>
            </div>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
Rockstar_ 17-Apr-13 1:39am    
Replace div with your textboxes....
you have to do this only

This is your javascript function

XML
<script type="text/javascript">

    function hideorshow(s) {
        debugger;
        if (s == 'Show') {
            //            var rdbs = document.getElementById("rdbShow").checked;
            //            var rdbh = document.getElementById("rdbHide").checked;

            //            if (rdbs == true) {
            document.getElementById('d1').style.display = "block";
            document.getElementById('rdbHide').checked = false;
        }
        if (s == 'Hide') {
            document.getElementById('d1').style.display = "none";
            document.getElementById('rdbShow').checked = false;
        }
return false;
    }

</script>



see i added " return false; at the end of the function.
 
Share this answer
 
you have to do this only

This is your javascript function

XML
<script type="text/javascript">

    function hideorshow(s) {
        debugger;
        if (s == 'Show') {
            //            var rdbs = document.getElementById("rdbShow").checked;
            //            var rdbh = document.getElementById("rdbHide").checked;

            //            if (rdbs == true) {
            document.getElementById('d1').style.display = "block";
            document.getElementById('rdbHide').checked = false;
        }
        if (s == 'Hide') {
            document.getElementById('d1').style.display = "none";
            document.getElementById('rdbShow').checked = false;
        }
return false;
    }

</script>



see i added " return false; at the end of the function.
and

<input type="radio" onclick="return hideorshow('Show');" id="rdbShow" value="Show" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900