File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how should i remove value in list box when i checked Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "how should i remove value in list box when i checked " Watch "how should i remove value in list box when i checked " New topic
Author

how should i remove value in list box when i checked

kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
hi
when i Checked dropbox the Value "Cash" in listbox should be removed;for that i have written code like this;i am able to remove "Cash" from list box but i am getting space in the list box;how should i remove space in the list box;
any help?

html
Script language="JavaScript"
function checkEntryType(){

if(document.frm.dropbox.checked == true)
{
for(var i=0;i document.frm.mode.length;i++){
if(document.frm.mode.options[i].text == "Cash"){
document.frm.mode.options[i].text=""
document.frm.mode.options[i].value=""

}
}
}



}
/script
form name=frm method=get action=""
Drop Box input type=checkbox name=dropbox value=drop
Mode of Payment
select name="mode"
option value=""/option
option value="Cash"Cash/option
option value="Cheque"Cheque/option
option value="Demand_Draft"Demand Draft/option
/form
/html
kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
hi
sorry i forgot to add one line in the above code
Drop Box<input type=checkbox name=dropbox value=drop on
click=checkEntryType()
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250
Here's something from the Quick References section on DevGuru.com:
You can use the options array to add options to, or delete options from any Select object. When adding or altering an option, you assign an Option object to a particular element of the array. The following code first creates an Option object called Folk, and then assigns it to element # 3 of the options array of a user-defined Select object called MusicType. If there is a value already assigned to element 3, it will be replaced by Folk, otherwise it will be created along with undefined elements at every index between the one created and the last existant one.

Code:
document.forms[0].musicType.options[3] = new Option("Folk", "folk", false, false)

Similarly, you can delete any option by assigning the value null to the appropriate element of the options array:

Code:
document.forms[0].musicType.options[2] = null

This will have the effect of removing element # 2 from the options array, and at the same time compressing the array so that element # 3 becomes # 2, element # 4 becomes # 3 etc. After deleting an option you must refresh the document by using history.go(0) at the end of the code. To determine which option of a Select object is currently selected, you can use the selectedIndex property along with the options property as follows:

Code:
document.forms[0].musicType.options.selectedIndex

...or you could simply use the selectedIndex property of the Select object:

Code:
document.forms[0].musicType.selectedIndex

Both the above lines of code return the number of the currently-selected index. If, however, the Select object allows for multiple selections (i.e. when the <SELECT> tag includes the MULTIPLE attribute), the selectedIndex property will only return the index of the first option selected. To determine all of the selected options, you would have to loop through the options array testing each option individually.
 
 
subject: how should i remove value in list box when i checked
 
Threads others viewed
how to take javascript array values in php form
Value to the textarea
can anyone tell me how do we update the values in servlet?
Dynamic drop down box
transfer data from text box to multiple select list box.
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture