...

View Full Version : Gremlin snuck into simple script



turpentyne
03-12-2012, 04:40 AM
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?

<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>

DanInMa
03-12-2012, 05:39 AM
well


$("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 :


$(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);
});
});



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum