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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    411
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Gremlin snuck into simple script

    I'm using this script to show/hide a field if its corresponding radio button is pressed. It was working. I moved on to work on other things on the page, and it stopped. Pulled it off onto its on page, and still no go.

    Any thoughts?
    PHP Code:
    <script>
    $(
    document).ready(function() {
        $(
    "div.desc").hide();
        $(
    "input[name$='hear']").click(function() {
            var 
    test = $(this).val();
            $(
    "div.desc").hide();
            $(
    "#" test).show();
            $(
    "div.desc").val("");
            $(
    "div.desc").attr("checked"false);
        });
    });


    </script>

    <table border=0><tr><td colspan="2" width=580><b>Please take a moment to help us with vital information for marketing purposes.<br />  Please be specific:</b></td></tr>
    <tr><td valign="top" colspan="2"><br>How did you hear about us?</td></tr>
        <tr><td width=195 valign=top>
        <div id="myRadioGroup">

    <input type="radio" name="hear" value="dcranch" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > DC Ranch Community <br />

    <input type="radio" name="hear" value="friend" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > From a friend <br />
    <input type="radio" name="hear" value="counselor" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > Counselor Referral <br />
    <input type="radio" name="hear" value="media" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > Media <br />
    <input type="radio" name="hear" value="other" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > Counselor Referral <br />
    </div>
    </td>
            
    <td valign=top>
    <div style="display: none;" id="dcranch" class="desc"> <input type="checkbox" value="Yes" name="resident" /> If so, are you a DC Ranch resident? )</div><br />    

    <div style="display: none;" id="friend" class="desc"> Name? <input type="text" name="how1" /></div><br />    
    <div style="display: none;" id="counselor" class="desc"> Name? <input type="text" name="how2" /></div><br />
    <div style="display: none;" id="media" class="desc"> Source? <input type="text" name="how3" /></div><br />
    <div style="display: none;" id="other" class="desc"> How? <input type="text" name="how4" /></div><br />
    </td>
    </tr></table> 

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    well

    Code:
            $("div.desc").val(""); 
            $("div.desc").attr("checked", false);
    div's dont have values or checkboxes. This code could never have worked as currently written.

    i think youre going for :

    Code:
    $(document).ready(function() { 
        $("div.desc").hide(); 
        $("input[name$='hear']").click(function() { 
            var test = $(this).val(); 
            $("div.desc").hide(); 
            $("#" + test).show(); 
            $("div.desc input").val(""); 
            $("div.desc input").attr("checked", false); 
        }); 
    });


  •  

    Posting Permissions

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