Hi All,

After much searching and head scratching I post you this!

I can't seem to find a generic way to handle multiple select data. The
function I use to receive form values will only pass the first selected
value from a multiple select. I have pasted part of the form and the
function below.

Thanks for any pointers,

Vince


// Example selectbox

<select name="countryarray[]" multiple="multiple">
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="GY">Alderney</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AM">Armenia</option>
<option value="AW">Aruba</option>
</select>


// Form Function

function getformvalues (fobj, valfunc){
                var str = "";
                aok = true;
                var val;
                //Run through a list of all objects within the form.
                for(var i = 0; i < fobj.elements.length; i++){
                        if(valfunc) {
                                if (aok == true){
                                        val = valfunc 
(fobj.elements[i].value,fobj.elements[i].name); 
                                        if (val == false){
                                                aok = false;
                                        }
                                }
                        }

                        if (fobj.elements[i].type == "checkbox") {
                                if (fobj.elements[i].checked) {
                                str += fobj.elements[i].name + "=" +
escape(fobj.elements[i].value) + "&";
                                } else {
                                str += fobj.elements[i].name + "=&";
                                } 

                        } else if (fobj.elements[i].tagName == "SELECT") {
                                var sel = fobj.elements[i];
                                str += sel.name + "=" +
sel.options[sel.selectedIndex].value + "&";
                
                        } else {
                                str += fobj.elements[i].name + "=" + 
escape(fobj.elements[i].value)
+ "&";
                        }
                }
                //Then return the string values.
                return str;
        }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to