Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need more information on dropdown list

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hey all, I have a question for ya all. I am dynamically making a drop down list looping with this command
Code:
document.Form.ElementId.options[x+1] = new Option(arrayOne[x],arrayOne[x]);
I do not want to use forms, is there a way to create the element without the form tag?

Thanks, -T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Give it an id and use document.getElementById() to target it to a variable... and then replace document.Form with your variable. Then it won't matter if you wrap the select in a form... although it's the wrong thing to do. If you would like some advice on how to do this the correct way... then show us the code you have and I'm certain some of us would love to advise.

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
HTML Code:
Code:
<label>State</label>
			<input type="text" id="state" class="tbSmall"  onclick="objState.displayState(inputState)">
			
			<form name="uState" id="uState" style="display:none">
				<select name="stateMenu" id="stateMenu"  onchange="objState.updateState(inputState)">
					<option>Select</option>
				</select>	
			</form>
			<script type="text/javascript">
				var inputState = {textDiv:'state',formDiv:'uState',selectDiv:'stateMenu', name:"userName",id:"userID",number:13,textbox:"state"};
</script>

So I have this text box that will house a state. When you click in it the text box will go to
Code:
$('state').style.display = 'none';
and the select drop down menu will then be shown by changing the form to
Code:
 $('uState').style.display = 'block';
I then pet a blob of data from an ajax request and then do this java function
Code:
function whatState(arrayOne)
{
	for(x=0;x<arrayOne.length;x++){
			document.uState.stateMenu.options[x+1] = new Option(arrayOne[x],arrayOne[x]);
			//document.stateMenu.options[x+1] = new Option(arrayOne[x],arrayOne[x]);
		}
}
So when I build the drop down list I have to use this dom modle, document.form.id.options = option(bla,bla).

I dont like using forms becuase of the behavior that forms can have in different browsers. So is there another way to build the options for the select elemet wo/ using a form tag?

Thanks for the help,

-T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Hi

While [tt]select[/tt] is a form element, it must be on a [tt]form[/tt]. Just ignore the fact that during the time the browsers were forced to forgive stupidity and display invalid documents which have form elements spread randomly without a [tt]form[/tt].

Anyway, if you just want to do it the wrong way, use this :
Code:
function whatState(arrayOne)
{
    for(x=0;x<arrayOne.length;x++){
        document.[red]getElementById('[/red]stateMenu[red]')[/red].options[x+1] = new Option(arrayOne[x],arrayOne[x]);
    }
}
But would be better to tell us about what different behavior are you talking. If it is the space around them, just remove it with style :
CSS:
form {
  padding: 0;
  margin: 0;
}

Feherke.
 
Thanks this was a great help.

-T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top