/// <summary>Gets the selected input by the given name attribute.
        /// E.g. there may be more than one input element (such as with radios); this is the active one.</summary>
        public Element this[string name] {
            get{
                List <Element> allWithName = Element.getElementsByAttribute("name", name);
                if (allWithName.Count == 0)
                {
                    return(null);
                }

                if (allWithName.Count == 1)
                {
                    return(allWithName[0]);
                }

                // We have more than one. If it's a radio, return the one which is selected.
                // Otherwise, return the last one.

                InputTag tag = ((InputTag)(allWithName[0].Handler));
                if (tag.Type == InputType.Radio)
                {
                    // Which is selected?
                    foreach (Element radio in allWithName)
                    {
                        if (((InputTag)(radio.Handler)).Checked)
                        {
                            return(radio);
                        }
                    }
                }
                return(allWithName[allWithName.Count - 1]);
            }
        }
        /// <summary>Submits this form.</summary>
        public void submit()
        {
            // Generate a nice dictionary of the form contents.

            // Step 1: find the unique names of the elements:
            Dictionary <string, string> uniqueValues = new Dictionary <string, string>();

            List <Element> allInputs = GetAllInputs();

            foreach (Element element in allInputs)
            {
                string type = element["type"];
                if (type == "submit" || type == "button")
                {
                    // Don't want buttons in here.
                    continue;
                }

                string name = element["name"];
                if (name == null)
                {
                    name = "";
                }

                // Step 2: For each one, get their value.
                // We might have a name repeated, in which case we check if they are radio boxes.

                if (uniqueValues.ContainsKey(name))
                {
                    // Ok the element is already added - we have two with the same name.
                    // If they are radio, then only overwrite value if the new addition is checked.
                    // Otherwise, overwrite - furthest down takes priority.
                    if (element.Tag == "input")
                    {
                        InputTag tag = (InputTag)(element.Handler);
                        if (tag.Type == InputType.Radio && !tag.Checked)
                        {
                            // Don't overwrite.
                            continue;
                        }
                    }
                }
                string value = element.value;
                if (value == null)
                {
                    value = "";
                }
                uniqueValues[name] = value;
            }

            FormData formData = new FormData(uniqueValues);

            // Hook up the form element:
            formData.form = Element;

            object result = Element.Run("onsubmit", formData);

            if (!string.IsNullOrEmpty(Action) && (result == null || !(bool)result))
            {
                // Post to Action.
                FilePath path = new FilePath(Action, Element.Document.basepath, false);

                FileProtocol fileProtocol = path.Handler;

                if (fileProtocol != null)
                {
                    fileProtocol.OnPostForm(formData, Element, path);
                }
            }
        }