Results 1 to 2 of 2

Thread: Javascript: Make elements appear based on user interaction

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    Javascript: Make elements appear based on user interaction

    How would I make an element visible/invisible based on user interaction with another element? For example: say I have two radio buttons: yes and no. If the user selects yes, a text field appears, and if no is selected it disappears. I don't need the code, just a starting point to do some learning on my own.
    Thanks for reading

  2. #2
    Join Date
    Feb 2009
    Location
    Monroe, NY
    Posts
    33

    Javascript/XHTML code for user's question

    Hi Mr Smith,
    That is an easy one. You could use the following code. It should be easy to understand but if you have any questions reply back.

    Code:
    <script type="text/javascript">
    function text_display(radio) {
        var some_text_element_id = document.getElementById('some_text');
        if(radio.value=='yes')
            some_text_element_id.style.display = 'block';
        else if(radio.value=='no')
            some_text_element_id.style.display = 'none';
    }
    </script>
    
    <input type="radio" onclick="text_display(this)" name="radio1" value="yes" />yes<br />
    <input type="radio" onclick="text_display(this)" name="radio1" value="no" />no<br />
    
    <div id="some_text" style="display:none">
    hello world
    </div>

Similar Threads

  1. A new simple way to make a image slider- Javascript Code
    By o0DarkEvil0o in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 18 May 2008, 04:52 PM
  2. The very simply way to make a image slider by Javascript
    By o0DarkEvil0o in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 16 May 2008, 04:11 PM

Posting Permissions

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