Jump to content
xisto Community
Sign in to follow this  
whistle

How To Dynamically Modify The Select Object? about add, remove...

Recommended Posts

I try to use javascript to dynamically modify a select object. That is, I hope to insert some new rows to or delete some rows from the select object.

 

The following is illustrated in the "http://www.w3schools.com/js/tryit.asp?filename=try_dom_select_remove;.

 

<html><head><script type="text/javascript">function formAction(){var x=document.getElementById("mySelect")x.remove(x.selectedIndex)}</script></head><body><form><select id="mySelect">	<option>Apple</option>	<option>Banana</option>	<option>Orange</option></select><input type="button" onclick="formAction()" value="Remove option"></form></body></html>

The x.remove() function does work. The toples in the select object can be removed one by one.

 

Then I find other methods described in "http://forums.xisto.com/no_longer_exists/;. There shows the add() function.

 

Methods

Syntax: object.method_name()

 

Method Description N IE W3C

add() Adds an option to the dropdown list  4 Yes

blur() Removes focus from the dropdown list 3 4 Yes

focus() Sets focus on the dropdown list 3 4 Yes

remove() Removes an option from the dropdown list 6 4 Yes

Then I try to replace the x.remove(x.selectedIndex) by x.add(), but the browser shows an error and nothing happens. I can't not find more detail of the add() method. Can anyone tell me how to use the add() method or where more detail is?

Share this post


Link to post
Share on other sites
How to pass selected value into scriptletHow To Dynamically Modify The Select Object?

How to pass selected value <like selcting combobox item JSP> into scriptlet

 

function loadFields(metadataModelId){   if(metadataModelId.Value == null)   metadataModelId.Value = document.ContainerTypeForm.MetadataModelId.Value;     <%   for(MetadataModel model:modelsList)   {   if(model.GetId().AsString().Equals(metadataModelId) /// here it is showing error

{     fields = model.GetAllMetadataFields();   }     }   %> }

-reply by venu

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.