Nov 22, 2009

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

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

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

whistle
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".

CODE
<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://www.w3schools.com/htmldom/dom_obj_select.asp". There shows the add() function.

QUOTE
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?

 

 

 


Comment/Reply (w/o sign-up)

(G)venu
How to pass selected value into scriptlet
How 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

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


Searching Video's for dynamically, modify, select, object, add, remove
See Also,
advertisement


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com