I have a select list that is populated using values from a text box. I also have two buttons: an add button that adds the entered value to the selection list and a delete button that removes the entered value from the selection list. I would like to do the following using jQuery:
- If the value entered in the text box is NOT AVAILABLE in the selection list, show the add button and hide the delete button.
- If the value entered in the text box is AVAILABLE in the selection list, hide the add button and show the delete button.
- If the EMPTY selection list shows the add button and hides the delete button.
Here is the code I came up with:
// Remove selected options $('#removeButton').click(function() { //$.map($('#addedchargeamtid :selected'), function(e) { $.map($('#addedchargeamtid option'), function(e) { var exp = $(e).text(); // Would like to have all the Option values in CVS format 0.00,1.99, etc... // If removed this should also remove the value in the array }) $('#removeButton').hide(); return !$('#addedchargeamtid :selected').remove(); }); // Add charge amount $('#addedchargeamtid option:selected').focus(function() { $('#removeButton').show(); });
The delete button is shown when I add the first value, but if I delete the value, the button will not display a backup.
UPDATE:
Ok, I edited it.
$('#removeButton').click(function() { $('#addedchargeamtid :selected').remove(); $.map($('#addedchargeamtid option'), function(e) { var exp = $(e).text(); alert(exp);
still does not hide the button when there is no value in SELECT. I also tried the option.
javascript jquery dhtml
Phill pafford
source share