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
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New problems with a form

    Code:
    <!--
        function toggle_visibility(id) {
           var e = document.getElementById(id);
           if(e.style.display == 'block')
              e.style.display = 'none';
           else
              e.style.display = 'block';
        }
    //-->
    </script>
    
    	<img id="top" src="top.png" alt="">
    	<div id="form_container">
    	<h1><a>Test Page</a></h1>
    	<form id="form_250840" class="appnitro"  method="post" action="">
    	<div class="form_description">
    
    <h2>TEST PAGE</h2>
    <p>QUESTIONNAIRE</p></div><ul>
    
    <div id="li_17" >
    <label class="description" for="element_17">Sample Question 1? </label>
    
    	<input type="radio" id="element_17_yes" name="element_17" class="element radio" value="yes" 	onclick="document.getElementById('li_17a').style.display='block';" />
        	<label class="choice" for="element_17_yes">Yes</label>
    	<input type="radio" id="element_17_no" name="element_17"   class="element radio" value="no" checked="checked"	onclick="document.getElementById('li_17a').style.display='none';" />
    	<label class="choice" for="element_17_no">No</label>
    </div>	
    
    
    <div id="li_17a" >
    <label class="description" for="element_17a">Sample Question 2? </label>
    	<span><input id="element_17_1a" name="element_17a" class="element radio" type="radio" value="1" />
    	<label class="choice" for="element_17_1a">Yes</label>
    	<input id="element_17_2a" name="element_17a" class="element radio" type="radio" value="2" checked="checked"/>
    	<label class="choice" for="element_17_2a">No</label></span>
    </div>	
    
    <li class="buttons">
    <input type="hidden" name="form_id" value="250840" />
    <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
    </li>
    </ul>
    Ok, my problem I seem to be having is that I want "sample question 2" to be invisible unless someone answers yes to "sample question 1". I've tried coding an onclick script into the radio buttons but I can't seem to get it working. I know this shouldn't be that difficult. Anyone know how to fix it?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You just forgot to iniitialize the div to non-display.

    That is:
    Code:
    <div id="li_17a" style="display: none;">
    Then it works fine.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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