puneetjava
puneetjava

Reputation: 165

Get value from jsp drop down in servlet

I have two drop down box , & the second drop down depends on what the user has selected in the first drop down(done using javascript). As shown below:

First drop down:

    <div class="element">
                    <label for="category">Category </label>
                    <select id='stateCombo' onchange='stateComboChange();'>
    <option value='-1' title='-select one-'>-select one-</option>
    <option value='0' title='Mobile'>Mobile</option>
    <option value='1' title='Nsw'>Routers</option>
    <option value='2' title='Tas'>Datacard</option>
</select>
                                        </div>

Second Drop down:

                <div class="element">
    <label for="category">Sub-Category </label>
    <select id='cityCombo' name="category" onchange='cityComboChange();'>
    <option value='-1' title='-select category first-'>-select category first-</option>
</select>
                </div>

Now i know how to get value from a particular field(say for input tag) in servlet, we use:

        request.getParameter("category");

But this statement doesn't work properly for drop down. It shows me the value=0, when i save it to my database. Please help me find the above solution.

Upvotes: 0

Views: 8035

Answers (2)

Ever Think
Ever Think

Reputation: 813

You have to check the javascript functions stateComboChange() and cityComboChange(). I think that functions changing the options tag in an unexpected way.

like the above answer you have to change value="0" to value="mobile" or you have to take out the value tag completely .

Upvotes: 4

Suresh Atta
Suresh Atta

Reputation: 121998

It shows me the value=0, when i save it to my database.

   <option value='0' title='Mobile'>Mobile</option>

You got selected Mobile.Since your value to that item is 0.You are getting that.

You might need to code like

<option value='Mobile' title='Mobile'>Mobile</option>

Upvotes: 1

Related Questions