dynamic div

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilbit02
    New Member
    • Nov 2007
    • 22

    dynamic div

    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
    [CODE=html]<select id="program" tabindex="2" onChange="revea l(choice)" name="program">
    [/CODE]


    Then I have the div with the name
    [CODE=html]<div id="prerequisit es_div"> </div>
    [/CODE]

    and then I have the function that handles the processing
    [CODE=javascript]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_d iv.innerHTML = prerequisites_d iv.innerHTML +

    "<td align='middle' bgcolor='white' colspan='2'>... .on and on to this" + n
    }
    else
    {
    return false;
    }

    }
    [/CODE]

    Can someone help me see this through or steer in the right way to get this accomplished.
    Last edited by gits; Dec 12 '07, 07:18 AM. Reason: fix code tags
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    u havent explained u problem what are u trying to d where from the prerecquisites are you showing from a database or what are the hardcoded if you are rettrieving from a database are u using xmlhttpresponse object or what the way yu have told no one is going to answere don shy tp show up ur code buddy no ones gonna cheat it[:D]
    Originally posted by lilbit02
    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
    Code:
    <select id="program" tabindex="2" onChange="reveal(choice)" name="program">

    Then I have the div with the name
    Code:
    <div id="prerequisites_div"> </div>
    and then I have the function that handles the processing
    Code:
    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;
                     }
    
    }
    Can someone help me see this through or steer in the right way to get this accomplished.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Use document.getEle mentById("prere quisites_div") to access the div element.

      To hide it, set the style.display property to "none". You could do this inline, e.g.
      [HTML]<div id="prerequisit es_div" style="display: none">...</div>[/HTML]

      To display the div, set the style.display property to "block".

      Comment

      Working...