Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting values from a <select> tag

Posted on 2006-11-24
6
Medium Priority
?
348 Views
Last Modified: 2013-11-19
Hi,
in my HTML I have this :

      <select size="5" name="HTTPs" style="width: 400px" id="idPathHTTPSelect">
      <%
            java.util.Iterator it1 = (java.util.Iterator) request.getAttribute("urlsList");
            while ( it1.hasNext() ) {
                  String url = (String) it1.next();
                  out.print("<option value=\""+url+"\">"+url);
            }
      %>
      </select>

In my Seervlet that handle the request I get a null value when trying to access the values of the select tag

System.out.println("Test : "+req.getParameterValues("HTTPs"));

>> Test : null
0
Comment
Question by:matthew016
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 500 total points
ID: 18009233
post your full JSP that represents the form (I hope you have one).
0
 
LVL 12

Assisted Solution

by:jessegivy
jessegivy earned 500 total points
ID: 18012117
...you'll need to close your option tags:

     <select size="5" name="HTTPs" style="width: 400px" id="idPathHTTPSelect">
     <%
          java.util.Iterator it1 = (java.util.Iterator) request.getAttribute("urlsList");
          while ( it1.hasNext() ) {
               String url = (String) it1.next();
               out.print("<option value=\""+url+"\">"+url</option>);
          }
     %>
     </select>

I also notice that you're using different values for the name and id attributes of your select tag which could be giving you problems using the req.getParameterValues function, try changing either id or name so that their values are the same.

as a side note the way I would write this code is like this(your code should work if close options):

     <select size="5" name="HTTPs" style="width: 400px" id="idPathHTTPSelect">
     <%
          java.util.Iterator it1 = (java.util.Iterator) request.getAttribute("urlsList");
          while ( it1.hasNext() ) {
               String url = (String) it1.next();
               %>
               <option value="<%=url%>"><%=url%></option>
          }
     %>
     </select>

...just a different way of writing the same thing :)

Cheers,

Jesse
0
 
LVL 11

Assisted Solution

by:Manish
Manish earned 500 total points
ID: 18013759
why>> System.out.println("Test : "+req.getParameterValues("HTTPs"));
If in select box ur able to select only one option..
String value=req.getParameter("HTTPs");
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Assisted Solution

by:summerian
summerian earned 500 total points
ID: 18017672
Is <select> tag in <form> tag?

Do you post the <form> with the "HTTPs" select tag to the servlet (pages may have many forms)?

Are there any options generated in the page, or is there empty <select> tag?
0
 
LVL 9

Author Comment

by:matthew016
ID: 18017826
I found out what was the problem ....

Actually I want to give all the elements in the select, and they are not selected.

I should make a javascript that selects them automatically on submit.
0
 
LVL 9

Author Comment

by:matthew016
ID: 18017835
jessegivy I put u as assisted but I'm not agree with your comment ;)

id and name must'nt be the same,
And your other way of writing gives the code less readable.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question