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
    Jul 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    keep form controls hidden

    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.

    Code:
    <html>
    <head>
    
    <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";  
        }
    }
    </script>
    
    </head>
    <body>
    
    <form>
    ...
    <p>3. Do you make purchase decisions for your company?<br>
    <input type="radio" id="purDecFlag0" name="purchaseDecision" 
        onclick="togglePurDec(event)">No 
    <input type="radio" id="purDecFlag1" name="purchaseDecision" 
        onclick="togglePurDec(event)">Yes 
    <div id="purchaseDecisionData" style="display:none; margin-left:20px">
    <p>
    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>
    </select>
    </p>
    <p>
    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>
    </div>
    </p>
    <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>
    </select>
    </p>
    ...
    </form>
    </body>
    </html>
    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?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to use a comparision operator (==) not and assignment operator (=)....

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

    .....Willy

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that did it! thanks very much.


  •  

    Posting Permissions

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