1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

dynamic div

Discussion in 'JavaScript' started by misslilbit02, Dec 11, 2007.

  1. #1
    Hey,

    What I'm trying to do is, based on a user selection from a drop down, dynamically show a div and it's contents. This is a short version of what I'm doing so code is missing.

    I have the select with the onChange
    <select id="program" tabindex="2" onChange="reveal(choice)" name="program">
    
    Code (markup):

    Then I have the div with the name
    <div id="prerequisites_div"> </div>
    
    Code (markup):
    and then I have the function that handles the processing
    function reveal(chosen)
    {
    
    
    	var n=1;
    	len = document.form1.program.length;
    	i = 0;
    	chosen = "none";
    
    	for (i = 0; i < len; i++) 
    	{
    		if (document.form1.program[i].selected)
    		{
    		
    		chosen = document.form1.program[i].value
    
    		} 
    	}
    	if (chosen == "BSN") 
    	{
    
    	prerequisites_div.innerHTML = prerequisites_div.innerHTML +
    	
    	"<td align='middle' bgcolor='white' colspan='2'>....on and on to this" + n
                     }
                     else
                     {
                     	return false;
                     }
    
    }
    
    Code (markup):
    Can someone help me see this through or steer in the right way to get this accomplished.
     
    misslilbit02, Dec 11, 2007 IP
  2. hrcerqueira

    hrcerqueira Peon

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To get the value:

    
    var chosen = document.getElementById('program').value;
    
    Code (markup):
    To set the pre requesites:

    
    document.getElementById('prerequisites_div').innerHTML += 'blah blah';
    
    Code (markup):
    Also, you can pass the select element directly to the onchange function, like this:

    
    <select tabindex="2" onChange="reveal(this)" name="program">
    
    Code (markup):
    and then to get the value, all you got to do is

    
    function reveal(select) {
       ...........
       var chosen = select.value;
       ............
       if (chosen == "BSN") {
                document.getElementById('prerequisites_div').innerHTML += 'blah blah';
       } else {
                return false;
       }
        ............
    }
    
    Code (markup):
     
    hrcerqueira, Dec 12, 2007 IP