SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help with Single RadioButton JS Problem

    What I am trying to do is make a single radiobutton works link a checkbox, click on, click off. But after many test, it looks like I have to have a line of code, such as alert(), in order to make it happen, any idea why? ( I don't want alert() pupops up ). Thanks in advance~!


    Code JavaScript:
    <script type="text/javascript">
    function on_off(id)
    {  
     
        if(document.getElementById(id).checked == false)
        {
            alert("Select VIP"); // function works with this line
            document.getElementById(id).checked = true;
        }
        else if(document.getElementById(id).checked == true)
        {
            alert("unSelect VIP");  // function works with this line
            document.getElementById(id).checked = false;
        }
     
     
    }
    </script>

    Code HTML4Strict:
    <input name="x_checker" id="x_checker" value="yes" checked="checked"  onfocus="on_off('x_checker')"  type="radio">

  2. #2
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    //Fixed. I think I got a logic wrong. Here is what i got finally:
     
     
        var flag = false;
        function on_off(id) {
                    //alert(flag == true);
            if (flag == true) {
                document.getElementById('x_checker').checked = false;
                flag = false;
            }
            else {
                document.getElementById('x_checker').checked = true;
                flag = true;
            }
        }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •