JavaScript Help

Discussion in 'JavaScript' started by red_fiesta, Nov 2, 2006.

  1. #1
    Hi,

    I have text on a page


    Env
    Lei
    Tour

    I want to make these place a select box next to it when its clicked.

    ie one clicks on Env and next to it will appear a select box and only next to Env.

    i guess the ahref will have to be a javascript command, i am just not sure how to do this

    Please help
     
    red_fiesta, Nov 2, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <script type="text/javascript">
    <!--
    function display_select(id)
    {
    	var objects = new Array('env', 'lei', 'tour');
    	
    	for (var i in objects)
    	{
    		var element = document.getElementById(objects[i]);
    		
    		element.style.display = element.id == id ? 'block' : 'none';
    	}
    	
    	return false;
    }
    //-->
    </script>
    <p>
    	<a href="#" onclick="return display_select('env');">Env</a>
    		<div id="env" style="display: none;">
    			<select>
    				<option>Env</option>
    			</select>
    		</div>
    </p>
    
    <p>
    	<a href="#" onclick="return display_select('lei');">Lei</a>
    		<div id="lei" style="display: none;">
    			<select>
    				<option>Lei</option>
    			</select>
    		</div>
    </p>
    
    <p>
    	<a href="#" onclick="return display_select('tour');">Tour</a>
    		<div id="tour" style="display: none;">
    			<select>
    				<option>Tour</option>
    			</select>
    		</div>
    </p>
    
    Code (markup):
     
    nico_swd, Nov 2, 2006 IP
  3. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That is cool, thanks

    one thing, i wanna make it on the same line i tried this..

    <a href="#" onclick="return display_select('tour');">Tour</a>
    <span id="tour" style="display:none;">
    <select>
    <option>Tour</option>
    </select>
    </span>

    but it still puts the select box on a new line... is there any way of doing this without using floats?
     
    red_fiesta, Nov 2, 2006 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    This should do it.
    
    <table border="0">
    <tr>
    	<td><a href="#" onclick="return display_select('env');">Env</a></td>
    	<td><div id="env" style="display: none;">
    			<select>
    				<option>Env</option>
    			</select>
    		</div>
    	</td>
    </tr>
    
    <tr>
    	<td><a href="#" onclick="return display_select('lei');">Lei</a></td>
    	<td><div id="lei" style="display: none;">
    			<select>
    				<option>Lei</option>
    			</select>
    		</div>
    	</td>
    </tr>
    
    <tr>
    	<td><a href="#" onclick="return display_select('tour');">Tour</a></td>
    	<td><div id="tour" style="display: none;">
    			<select>
    				<option>Tour</option>
    			</select>
    		</div>
    	</td>
    </tr>
    </table>
    
    Code (markup):
     
    nico_swd, Nov 2, 2006 IP
  5. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hihi

    i meant to say no tables as well

    sorry :)
     
    red_fiesta, Nov 2, 2006 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Try asking here.
    forums.digitalpoint.com/forumdisplay.php?f=39
     
    nico_swd, Nov 2, 2006 IP