Solved

Getting values from a <select> tag

Posted on 2006-11-24
6
338 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now