View Full Version : keep form controls hidden

12-10-2004, 08:22 PM
I am going to use the following code in my website for hiding and showing fields I need hidden unless a correct radio button is pressed.


<script type="text/javascript" language="JavaScript">
function togglePurDec(evt) {
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
var block = document.getElementById("purchaseDecisionData");
if (target.id = "purDecFlag1") {
block.style.display = "block";
} else {
block.style.display = "none";


<p>3. Do you make purchase decisions for your company?<br>
<input type="radio" id="purDecFlag0" name="purchaseDecision"
<input type="radio" id="purDecFlag1" name="purchaseDecision"
<div id="purchaseDecisionData" style="display:none; margin-left:20px">
3a. What is your purchase budget for the current fiscal year?
<select name="PurBudget">
<option value="">Choose One:</option>
<option value="1">Less than $50,000</option>
<option value="2">$50,000-100,000</option>
<option value="3">$100,000-500,000</option>
<option value="4">$500,000+</option>
3b. What role do you play in purchase decisions? (check all that apply)<br>
<input type="checkbox" name="purRole1">Research<br>
<input type="checkbox" name="purRole2">Recommend<br>
<input type="checkbox" name="purRole3">Review Recommendations of Others<br>
<input type="checkbox" name="purRole4">Sign Purchase Orders<br>
<input type="checkbox" name="purRole5">None of the above<br>
<p>4. How long have you been at your current employment position?
<select name="emplLen">
<option value="">Choose One:</option>
<option value="1">Less than 6 months</option>
<option value="2">6-12 months</option>
<option value="3">1-2 years</option>
<option value="4">2+ years</option>

The problem is that it shows my hidden boxes if I click on 'No' or if I click on 'Yes'. I'm just learning javascript so I'm at a loss as to why it would do it for each button. Could someone help me out?

Willy Duitt
12-10-2004, 09:19 PM
You need to use a comparision operator (==) not and assignment operator (=)....

if (target.id == "purDecFlag1") {


12-10-2004, 09:42 PM
that did it! thanks very much.