Solved

Getting values from a <select> tag

Posted on 2006-11-24
6
341 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
6 Comments
 
LVL 12

Accepted Solution

by:
enachemc earned 125 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 125 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 125 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Assisted Solution

by:summerian
summerian earned 125 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

828 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