How to removed selected options via Javascript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea Grant
    New Member
    • Jan 2011
    • 1

    How to removed selected options via Javascript?

    I am new to javascript and this is all trial and error. When a user selects an option, the Id of teh option is added to a hidden form field, creating a list of id's. Each ID is displayed on the page. If you click the ID it should delete the id from the hidden form field and from view. The javascript below deletes the whole element. I have searched high and low but can not find anythning to help me remove the ID's when the user clicks the ID.

    Code:
    function deletef1_id(f1id){
    							var x = document.forms[0].elements[f1id]; 
    							x.parentNode.removeChild(x); 
    							
    				}
    Code:
    <div id="return_list_f1" style="background-color:cab4cd;padding:5px 0 5px;" name="return_list_f1">this is where the list of id's will appear as links</div>
    
    <form action="test.cfm" method="post" name="feature" id="feature">
    					<input type="hidden" name="f1_id" id="f1_id">
    					<input type="hidden" name="f2_id" id="f2_id">
    					<input type="submit" name="submit" value="submit">
    				</form>
    thanks to anyone who can help
    Andrea
    Last edited by Niheel; Jan 26 '11, 03:39 PM.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Not sure if I completely understand your request or not but I'll give it a shot.

    Try using the ID property of the element.
    Code:
    function deletef1_id(f1id){
                                var x = document.forms[0].elements[f1id]; 
                                x.id = ""; 
                    }
    This will set the id of an element to an empty string.

    Comment

    Working...