carlg Posted August 31, 2007 Share Posted August 31, 2007 I want to do a multiple select like this where the user can select multiple items <SELECT NAME="abc" MULTIPLE> <OPTION VALUE="A">A <OPTION VALUE="B">B <OPTION VALUE="C">C <OPTION VALUE="D">D </SELECT> How do I reference these variable in code or the form that does the processing? Thanks for the info Carl Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/ Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 Depening on whether you use "method=post" or "method=get" in your <form> tag, the value of the selected option would be in $_POST['abc'] or $_GET['abc'], respectively. Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338703 Share on other sites More sharing options...
carlg Posted August 31, 2007 Author Share Posted August 31, 2007 But, what if the user selects 2 options? Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338708 Share on other sites More sharing options...
carlg Posted August 31, 2007 Author Share Posted August 31, 2007 I will be using $_POST Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338709 Share on other sites More sharing options...
sasa Posted August 31, 2007 Share Posted August 31, 2007 change name property to "abc[]" Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338710 Share on other sites More sharing options...
carlg Posted August 31, 2007 Author Share Posted August 31, 2007 and then how is it referenced in the processing script? For exmaple if I do a count() on the incoming array and the user selected 2 options Will my count be 2 or 4? Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338718 Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 count($_POST['abc']) should be the number of fields with the name "abc[]" that were submitted. Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338721 Share on other sites More sharing options...
carlg Posted August 31, 2007 Author Share Posted August 31, 2007 Great, thanks for the help. I got everything working besides 1 thing. How do you get that variable to work in a Javascript? I have something like this <SELECT NAME="abc[]"></SELECT> How can I refer to abc in a javascript? Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338881 Share on other sites More sharing options...
roopurt18 Posted August 31, 2007 Share Posted August 31, 2007 Give it an id="abc" and use document.getElementById() You can also try: document.formName["abc[]"] Quote Link to comment https://forums.phpfreaks.com/topic/67466-multiple-selects/#findComment-338883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.