Solved

Getting values from a <select> tag

Posted on 2006-11-24
6
345 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

623 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