Menu

Can I retrieve a value in a select?

Help
sandra81
2005-03-30
2013-06-03
  • sandra81

    sandra81 - 2005-03-30

    Here my problem...
    I have a select tag which perform a list of suppliers.
    When I choose a supplier in the list I want open a new window with a list with the products supplied by this supplier.
    So I want to pass id_supplier in parameter.
    Can I retrieve the value of id_supplier choosed in the list?
    And how can I do?

    Here my code :

    <db:select fieldName="id_supplier" styleClass="clsSelectStyle" onChange="javascript:window.open('/appli_test/alter_purchase_product_list.jsp?&supplier=5')">

    "5" is for example, but I want retrieve value of id_supplier choosed in the list.

     
    • Henner Kollmann

      Henner Kollmann - 2005-03-30

      Have a look at the bookstore//howto/howtoChangeSelectBox.jsp. This should fit your needs!

      Cheers,
      Henner

       
    • sandra81

      sandra81 - 2005-03-31

      Hi Henner,

      Thanks a lot for your answer but it doesn't work.
      Select doesn't keep the focus on the value selected so I haven't, in the second select, the correct values. Can you help me??

      Thanks in advance.

       
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        I you build an example based on bookstore i can try to help...

        Henner

         
    • sandra81

      sandra81 - 2005-03-31

      I built an example based on bookstore, I found the problem.
      So it works when I don't have a given table... but I have a given table.
      How to do?

      Thanks a lot !

       
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        Send me the example please!

         
    • sandra81

      sandra81 - 2005-03-31

      Here my example :

      <head>
      <%@ taglib uri="/WEB-INF/dbforms.tld" prefix="db" %>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Purchase</title>
      <db:base/>
      </head>

      <body>
      <db:dbform autoUpdate="false" followUp="/test.jsp" tableName="alter_purchase_purchase" maxRows="2">
          <db:select fieldName="id_supplier" onChange="this.form.submit();">
          <db:tableData
                  name="id_supplier"
                  foreignTable="alter_directory_company"
                  visibleFields="name"
                  storeField="id_company"
              />
          </db:select>
          <db:select fieldName="ref_iph">
              <db:queryData name="ref_iph"
              query='<%=     "SELECT DISTINCT ref_iph " +
                          "FROM alter_achat_produit " +
                          "WHERE id_supplier = " +
                          org.dbforms.util.ParseUtil.getParameter(request, "id_supplier", "-1")
                     %>'
              />
          </db:select>
      </db:dbform>
      </body>
      </html>

       
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        But this example is'nt based on bookstore - so i have no change to reproduce your problem....

         
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        Could you try an disableCache="true" in your tableData and  queryData tag?

        The default value is false, so that each query is calculated only once, data is cached.

        Henner

         
    • sandra81

      sandra81 - 2005-03-31

      Sorry, there is an error.
      maxRows="*" (not maxRows="2")

       
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        And now it's working?

         
    • sandra81

      sandra81 - 2005-03-31

      No, it's the same.

       
    • sandra81

      sandra81 - 2005-03-31

      In the bookstore example there is :
      <!--- To force an reload event.
             This is necessary because we have no given table and needs and reload event to refetch the values of the select boxes!                
      Is first parameter here because we do not have a tablename. In this special case the hidden input field customEvent is not rendered! -->           

      <input type="hidden" name="customEvent" value="re_0_0"/>

      Could you explain me "Is first parameter here because we do not have a tablename.". I have tablename in my dbform. So can I use org.dbforms.util.ParseUtil.getParameter(request, "books", "-1")?
      In addition, I don't understand what is the event in input tag. What is its use?

       
      • Henner Kollmann

        Henner Kollmann - 2005-03-31

        We need a reload event. Because tablename is empty we must generate one.

         
    • tankdriver

      tankdriver - 2005-10-05

      I want to do something similar such as populate a select box given what a user selected in another select box on the same form.  I am able to get the second select box to populate but the value that the user selected in the first select goes back to the original value after the form is submitted.  I cannot figure out how to keep the new value in the first select after the form gets submitted.

      Another question is why do I have to use the wierd syntax "f_0_0@root_8" to access a request parameter?  I would assume that "SERVICE_NAME" would be the parameter name but when I interogate the request it is called "f_0_0@root_8".  I do have the table name specified in the form tag.

      This is the code for the two selects. 

      <db:message key="SERVICE_NAME"/></td>

      <db:select fieldName="SERVICE_NAME" onChange="this.form.submit();">
          <db:tableData disableCache="true"
              name="SERVICE_NAME"
              visibleFields="SERVICE_NAME"
              foreignTable="sre_service_info"
              storeField="SERVICE_NAME"
          />
      </db:select>

      <db:message key="OPTION_SET_NAME"/></td>

      <% String myselect = "SELECT option_set_name, option_set_name "    +
                          "from sre_service_option_set " +
                          "WHERE service_name = '" +
                          org.dbforms.util.ParseUtil.getParameter(request, "f_0_0@root_8", "") +
                          "'";
      %>

      <db:select fieldName="OPTION_SET_NAME" >
          <db:queryData disableCache="true"
              name="OPTION_SET_NAME"
              query="<%= myselect
                      %>"
          />
      </db:select>

      Any help would be appreciated.  Thanks!

       
      • Henner Kollmann

        Henner Kollmann - 2005-10-05

        Have a look at the bookstore//howto/howtoChangeSelectBox.jsp. This should fit your needs!

        Cheers,
        Henner

         

Log in to post a comment.

MongoDB Logo MongoDB