| | |
Single variable multiple select box
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
Hi,
I created a multiple select box wich i would like to have one variable with all the results selected on the multiple select box such as variable_name = "result1|result2|result3"
This is what i have so far:
Now what i exactly need is to have a variable called "test" outside of the loop wich i have all the selected results separated with an "|", so that when i do alert(test) displays all results as a one result.
Hope someone can help
Thanks
I created a multiple select box wich i would like to have one variable with all the results selected on the multiple select box such as variable_name = "result1|result2|result3"
This is what i have so far:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
oSelect = document.getElementById ('s1'); var iNumSelected = 0; for (var iCount=0; oSelect.options[iCount]; iCount++) { if (oSelect.options[iCount].selected == true) { iNumSelected ++; alert(oSelect[iCount].value); // this part alerts all the result within the loop } }
Now what i exactly need is to have a variable called "test" outside of the loop wich i have all the selected results separated with an "|", so that when i do alert(test) displays all results as a one result.
Hope someone can help
Thanks
Declare a variable 'test' outside the loop and inside the loop append the value of the selected option along with a '|' to `test'. Try it. Did you get the desired result? If no, then why? What seems to be missing here? What do you think needs to be done to make it work the way you expect?
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 1
javascript Syntax (Toggle Plain Text)
oSelect = document.getElementById ('s1'); var iNumSelected = 0; var str=""; for (var iCount=0; oSelect.options[iCount]; iCount++) { if (oSelect.options[iCount].selected == true) { iNumSelected ++; str+= "|" + oSelect.options[iCount].value } } alert(str);
Last edited by cscgal; Sep 26th, 2008 at 7:39 pm. Reason: Added code tags
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 1
javascript Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script> function show() { var ss= document.getElementById('s1'); var len= ss.options.length; var str=""; var j=0; for(var i=0;i<len;i++){ if(ss.options[i].selected == true) { if(j == 0) str= ss.options[i].innerHTML; else str += '|' + ss.options[i].innerHTML; j++; } } alert(str); } </script> </HEAD> <BODY> <select id="s1" size=3 multiple> <option> Raja1 </option> <option> Raja2 </option> <option> Raja3 </option> <option> Raja4 </option> <option> Raja5 </option> </select> <div> <input type="button" onclick="show();"> </div> </BODY> </HTML>
I think this can help u.
Last edited by cscgal; Sep 26th, 2008 at 7:39 pm. Reason: Added code tags
![]() |
Similar Threads
- Tutorial: An introduction to Test Driven Development (Computer Science)
- Using OpenGL in Visual C++: Part I (Game Development)
- not-a-virusadware (Viruses, Spyware and other Nasties)
- Set Performance Options in Windows XP (Windows tips 'n' tweaks)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: image as link
- Next Thread: Drop Down Menu with Sucker Fish
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array automatically beta blackjack boarder box browser captcha captchaformproblem card cart close codes column css date debugger decimal dependent design developer dom download element embed enter error events firefox focus form frameworks game getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 iframe index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp libcurl listbox maps marquee masterpage media menu microsoft mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software sources starrating synchronous toggle tweet unicode validation variables w3c webservice window windowofwords xml






