Current location: Hot Scripts Forums » General Web Coding » JavaScript » gather select options and fill div


gather select options and fill div

Reply
  #1 (permalink)  
Old 12-12-05, 02:50 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
gather select options and fill div

Hi

I have a <select> with about 20 options.. I know very basic JS so i'm stuck..
I want users to be able to select multiple options and then after they have selected them, JS will gather them and, foreach option create a line of html like this
Code:
 <input type="text" name="[OPTION VALUE HERE]"/><br/>
then, it wil gather these strings of html and insert them into the div updateForm

I can do the updating the div, but the gathering the selected options and creating the string I dont know how to do...

help ?
Reply With Quote
  #2 (permalink)  
Old 12-14-05, 03:15 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
That's pretty easy. The select element has an options collection containing all the sub elements. We just need to loop through that collection and append some new data to a string which will represent the complete HTML.


Code:
var htmlString=""
var select=document.getElementById('selectElementId')
for(var i=0;i<select.options.length;i++){
 if(select.options[i].selected){
  htmlString+="<input type='text' name="+ select.options[i].value +"/><br/>"
 }
 document.getElementById('updateForm').innerHTML=htmlString
}
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 01-14-07, 07:14 AM
funny_shrshr funny_shrshr is offline
Newbie Coder
 
Join Date: Nov 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
I want to remove these selected options ... how ??
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I populate a dropdown list???? zorrox02 JavaScript 4 10-01-04 04:03 AM


All times are GMT -5. The time now is 10:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.