Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    check a radio button when a textbox is populated

    i was wondering if it could be possible to mark a radio button as "checked" if the textbox beside it is clicked, or populated? Thanks..

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Here's an example:
    Code:
    <script type="text/javascript">
    <!--
    /*<![CDATA[*/
    function bstatus(t,x) {
    (x>0)? document.getElementById(t).checked=true:
           document.getElementById(t).checked=false;
    }
    /*]]>*/
    // -->
    </script>
    
    
    <form name="f" id="f" method="post" action="" enctype="application/x-www-form-urlencoded">
    <input type="text" name="t1" id="t1" value="" size="35" maxlength="300" onchange="bstatus('rb1',this.value.length)" />
    <input type="radio" name="rb1" id="rb1" />
    <br /><input type="text" name="t2" id="t2" value="" size="35" maxlength="300" onchange="bstatus('rb2',this.value.length)" />
    <input type="radio" name="rb2" id="rb2" />
    </form>
    Last edited by rwedge; 09-21-2005 at 04:18 AM. Reason: missing id value

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rwedge
    Here's an example:
    Code:
    <script type="text/javascript">
    <!--
    /*<![CDATA[*/
    function bstatus(t,x) {
    (x>0)? document.getElementById(t).checked=true:
           document.getElementById(t).checked=false;
    }
    /*]]>*/
    // -->
    </script>
    
    
    <form name="f" id="f" method="post" action="" enctype="application/x-www-form-urlencoded">
    <input type="text" name="t1" id="t1" value="" size="35" maxlength="300" onchange="bstatus('rb1',this.value.length)" />
    <input type="radio" name="rb1" id="" />
    <br /><input type="text" name="t2" id="t2" value="" size="35" maxlength="300" onchange="bstatus('rb2',this.value.length)" />
    <input type="radio" name="rb2" id="rb2" />
    </form>
    You use document.getElementById and grab the first argument, but the value you provide as the first argument when calling the function is a name and not a Id :P


  •  

    Posting Permissions

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