469,898 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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.

Expand|Select|Wrap|Line Numbers
  1. function deletef1_id(f1id){
  2.                             var x = document.forms[0].elements[f1id]; 
  3.                             x.parentNode.removeChild(x); 
  4.  
  5.                 }
  6.  
Expand|Select|Wrap|Line Numbers
  1. <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>
  2.  
  3. <form action="test.cfm" method="post" name="feature" id="feature">
  4.                     <input type="hidden" name="f1_id" id="f1_id">
  5.                     <input type="hidden" name="f2_id" id="f2_id">
  6.                     <input type="submit" name="submit" value="submit">
  7.                 </form>
thanks to anyone who can help
Andrea
Jan 26 '11 #1
1 1321
JKing
1,206 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. function deletef1_id(f1id){
  2.                             var x = document.forms[0].elements[f1id]; 
  3.                             x.id = ""; 
  4.                 }
  5.  
This will set the id of an element to an empty string.
Jan 26 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by TJ Walls | last post: by
5 posts views Thread by bigfella | last post: by
2 posts views Thread by Jim Corey | last post: by
9 posts views Thread by Matthew Wells | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.