RayLoveless
RayLoveless

Reputation: 21108

html; how to add a select drop-down to a form

I'm wondering how I can add a select list to a from. Here's my form

<form action="/myPath" id="frmSearch" method="post">

              <input id="AgeMaxTxBx" name="AgeMaxTxBx" style="width: 30px" type="text" value="120" />            


                <select id="country" multiple>
   <option value="China">China</option>
   <option value="Japan">Japan</option>
   <option value="United State">United State</option>
   </select>


                <a href="javascript:submitSearch()">submit Form</a>

            </form>

and here is the code that's parsing my form data:

 var formData = Request.Form;
        foreach (string key in formData.AllKeys)
        {
            string val = formData[key];
        }

I'm only seeing the "AgeMaxTxBx" key in my for loop. I hope what I'm trying to do makes sense. How might one accomplish this? I would like to select multiple countries also.

Upvotes: 0

Views: 119

Answers (1)

Nick Craver
Nick Craver

Reputation: 630627

An element needs to have a name attribute to be included in the <form> submit data, like this:

<select id="country" name="country" multiple>

Once you add this you'll see it in your keys.

Upvotes: 1

Related Questions