| | |
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.
•
•
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 |
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser captchaformproblem cart child close codes column css date debugger decimal dependent design disablefirebug dom download element embed engine enter error events ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index java javascript javascripthelp2020 jawascriptruntimeerror jquery jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php player position post problem programming prototype redirect safari scale scriptlets scroll search security select software sql toggle unicode variables w3c web website window windowofwords \n






