Solved

Getting values from a <select> tag

Posted on 2006-11-24
6
340 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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…
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:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 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