14 Replies Latest reply: Dec 3, 2012 8:15 AM by Prabodh RSS

    Multiple Values Tabular form

    695721
      Dears ,
      1- I have tabular form
      select 
      "ROWID",
      "ORDER_ID",
      "LOCATION_ID",
      PLACE_FROM,
      PLACE_TO,
      DELIVERY_PRICE
      from "#OWNER#"."ORDER_LOCATION"
      WHERE ORDER_ID = :P3_ORDER_ID
      2- Build application process named (ORDER_PROCESS)
      declare
       px01 varchar2(100) := dbms_assert.enquote_literal(apex_application.g_x01);
       V_PLACE_FROM   varchar2(30);
       V_PLACE_TO   varchar2(30);
       V_DELIVERY_PRICE  NUMBER;
       v_sql varchar2(1000) := 'select get_state_name(place_to) place_to_state,get_state_name(place_from) place_from_state,
      place_to,DELIVERY_PRICE
      from LOCATION_SHEET WHERE  LOCATION_ID = ';
      begin
         v_sql := v_sql || px01;
         execute immediate v_sql into V_PLACE_FROM,V_PLACE_TO,V_DELIVERY_PRICE;
        htp.prn(V_PLACE_FROM);
        htp.prn(V_PLACE_TO);
        htp.prn(V_DELIVERY_PRICE);
      exception
       when others then 
         NULL;
      end;
      3- In html header page i put this javascript code to get (place_to , place_from , delivery_price) when i choose location_if from select list
      <script type="text/javascript">
      function getlocation(pThis) {
         var tid = pThis.id.replace("f04","f05","f06","f07");
         ajaxRequest = new  htmldb_Get(
                       null,$v('APP_ID'),'APPLICATION_PROCESS=ORDER_PROCESS',0); 
         ajaxRequest.addParam('x01',$v(pThis));
         ajaxResponse = ajaxRequest.get(); 
         $s(tid,ajaxResponse );
      }
      </script>
      4- in location_id column i put in Element Attributes : onchange="getlocation(this);"

      but when i choose from location_id (select list ) not get the values in behind column (place_to , place_from , delivery_price) , what's the problem please

      Ahmed
        • 1. Re: Multiple Values Tabular form
          Prabodh
          What do you get in ajaxresponse? You could add an alert to check the value returned to ajaxresponse.

          My guess is that you get only one value, V_PLACE_FROM. Is that right?

          Cheers,
          • 2. Re: Multiple Values Tabular form
            695721
            please
            on Element Attributes : onchange="getlocation(this);"
            how can i add multiple function
            • 3. Re: Multiple Values Tabular form
              evrm
              Hi Ahmed,

              If you want to place the values you get back from you ajax call to the application process into items in your page, place them in some xml format. This way you can parse this xml in the javascript function and fill the page items. Take a look at this obe example http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/hol08/apexweb20/ajax_otn.htm

              regards,
              Erik-jan
              • 4. Re: Multiple Values Tabular form
                695721
                Hi Erik-jan ,
                it's possible to use this solution in tabular form ?
                Regards,
                Ahmed
                • 5. Re: Multiple Values Tabular form
                  Prabodh
                  please
                  on Element Attributes : onchange="getlocation(this);"
                  how can i add multiple function>
                  onchange="getlocation(this);getfunction2(this);getfunction3(this);....."
                  Asking the wrong questions will get you wrong answers, most of the time.

                  If the objective is to receive and process the 3 values separately then try this.
                     v_sql := v_sql || px01;
                     execute immediate v_sql into V_PLACE_FROM,V_PLACE_TO,V_DELIVERY_PRICE;
                    htp.prn(V_PLACE_FROM||':'||V_PLACE_TO||':'||V_DELIVERY_PRICE);
                  exception
                  <script type="text/javascript">
                  function getlocation(pThis) {
                     var tid = pThis.id.replace("f04","f05","f06","f07");
                     ajaxRequest = new  htmldb_Get(
                                   null,$v('APP_ID'),'APPLICATION_PROCESS=ORDER_PROCESS',0); 
                     ajaxRequest.addParam('x01',$v(pThis));
                     ajaxResponse = ajaxRequest.get();
                    // new code
                     var vals = ajaxResponse.split(":"); 
                    // $s(tid,ajaxResponse );
                    $s(tid,vals[0] );
                    $s(<other field>,vals[1] );
                    $s(<yet other field>,vals[2] );
                  }
                  PS:
                  The above assumes that your data does not contain : (colon) character. If it does then use a character that cannot occur in the data, e.g. ~

                  Edited by: Prabodh on Dec 3, 2012 2:39 PM
                  • 6. Re: Multiple Values Tabular form
                    695721
                    Hi Prabodh ,
                    i am try to do your custom code but still not working
                    this the query in tabular form
                    select 
                    "ORDER_LOC",
                    "ORDER_ID",
                    "LOCATION_ID" ,
                    null  PLACE_FROM,
                    null  PLACE_TO,
                    null  DELIVERY_PRICE
                    from "#OWNER#"."ORDER_LOCATION"
                    where "ORDER_ID" = :P56_ORDER_ID
                    and this the query in application process after your custom
                    declare
                     px01 varchar2(100) := dbms_assert.enquote_literal(apex_application.g_x01);
                     V_PLACE_FROM   varchar2(30);
                     V_PLACE_TO   varchar2(30);
                     V_DELIVERY_PRICE  NUMBER;
                     v_sql varchar2(1000) := 'select get_state_name(place_to) place_to_state,get_state_name(place_from) place_from_state,
                    place_to,DELIVERY_PRICE
                    from LOCATION_SHEET WHERE  LOCATION_ID = ';
                    begin
                      v_sql := v_sql || px01;
                       execute immediate v_sql into V_PLACE_FROM,V_PLACE_TO,V_DELIVERY_PRICE;
                      htp.prn(V_PLACE_FROM||':'||V_PLACE_TO||':'||V_DELIVERY_PRICE);
                    exception
                     when others then 
                       NULL;
                    end;
                    and this javascript code
                    <script type="text/javascript">
                    function getlocation(pThis) {
                       var tid = pThis.id.replace("f05","f06","f07","f08");
                       ajaxRequest = new  htmldb_Get(
                                     null,$v('APP_ID'),'APPLICATION_PROCESS=ORDER_PROCESS',0); 
                       ajaxRequest.addParam('x01',$v(pThis));
                       ajaxResponse = ajaxRequest.get();
                      // new code
                       var vals = ajaxResponse.split(":"); 
                      // $s(tid,ajaxResponse );
                      $s(tid,vals[0] );
                      $s(<other field>,vals[1] );
                      $s(<yet other field>,vals[2] );
                    }
                    </script>
                    what's the problem ?
                    • 7. Re: Multiple Values Tabular form
                      Prabodh
                      You have not spelt out what you want to do. The code snippet I gave obviously needs changes to be made by you.

                      To start with what is this line supposed to do in your code?
                      var tid = pThis.id.replace("f05","f06","f07","f08");
                      Check out the syntax for String replace() method here, http://www.w3schools.com/jsref/jsref_replace.asp

                      If you elaborate on what this line is meant to do it might be possible to give you better code snippet.

                      Cheers,
                      • 8. Re: Multiple Values Tabular form
                        695721
                        Prabodh wrote:
                        If you elaborate on what this line is meant to do it might be possible to give you better code snippet.
                        i am try to get the code but i am not a ware with javascript

                        Thank you
                        • 9. Re: Multiple Values Tabular form
                          Prabodh
                          i am try to get the code but i am not a ware with javascript
                          Explain in plain English. What are f05..f08? Which fnn is location id? What are you trying to accomplish with that replace statement?
                          • 10. Re: Multiple Values Tabular form
                            695721
                            when choose from select list (location_id)
                            get the values in behind column (place_to , place_from , delivery_price)
                            this the column in tabular form
                                 [row selector]
                                 ORDER_LOC
                                 ORDER_ID
                                 LOCATION_ID
                                 PLACE_FROM
                                 PLACE_TO
                                 DELIVERY_PRICE
                            • 11. Re: Multiple Values Tabular form
                              695721
                              i put demo in apex.oracle.com
                              workspace:elnoor
                              user:ahmed
                              pass:123
                              application name : Application 24605 - ORDERS
                              this the DDL Code that i use
                              CREATE TABLE  "LOCATION_SHEET" 
                                 (     "LOCATION_ID" NUMBER NOT NULL ENABLE, 
                                   "PLACE_FROM" NUMBER, 
                                   "PLACE_TO" NUMBER, 
                                   "DELIVERY_PRICE" NUMBER, 
                                    CONSTRAINT "LOCATION_SHEET_PK" PRIMARY KEY ("LOCATION_ID") ENABLE
                                 )
                              /
                              CREATE TABLE  "ORDER_LOCATION" 
                                 (     "ORDER_ID" NUMBER NOT NULL ENABLE, 
                                   "LOCATION_ID" NUMBER NOT NULL ENABLE, 
                                   "ORDER_LOC" NUMBER
                                 )
                              /
                              ALTER TABLE  "ORDER_LOCATION" ADD CONSTRAINT "ORDER_LOCATION_R01" FOREIGN KEY ("ORDER_ID")
                                     REFERENCES  "ORDERS" ("ORDER_ID") ENABLE
                              /
                              ALTER TABLE  "ORDER_LOCATION" ADD CONSTRAINT "ORDER_LOCATION_R02" FOREIGN KEY ("LOCATION_ID")
                                     REFERENCES  "LOCATION_SHEET" ("LOCATION_ID") ENABLE
                              /
                              
                              CREATE OR REPLACE FUNCTION  "GET_STATE_NAME" (p_st  DEMO_STATES.st%type) RETURN varchar2 IS
                              v_state_name  DEMO_STATES.state_name%type;
                              /******************************************************************************
                                 NAME:       get_state_name
                                 PURPOSE:    
                              
                                 REVISIONS:
                                 Ver        Date        Author           Description
                                 ---------  ----------  ---------------  ------------------------------------
                                 1.0        28/11/2012          1. Created this function.
                              
                                 NOTES:
                              
                                 Automatically available Auto Replace Keywords:
                                    Object Name:     get_state_name
                                    Sysdate:         28/11/2012
                                    Date and Time:   28/11/2012, 03:38:31 م, and 28/11/2012 03:38:31 م
                                    Username:         (set in TOAD Options, Procedure Editor)
                                    Table Name:       (set in the "New PL/SQL Object" dialog)
                              
                              ******************************************************************************/
                              BEGIN
                              
                                select state_name into v_state_name
                                from DEMO_STATES
                                where st =p_st;
                                
                                return(v_state_name);
                                  
                                exception when no_data_found then
                                return('');
                              END get_state_name; 
                              /
                              • 12. Re: Multiple Values Tabular form
                                Prabodh
                                Check out your page now.
                                <script type="text/javascript">
                                function getlocation(pThis) {
                                   //var tid = pThis.id.replace("f05","f06","f07","f08");
                                   var tid = pThis.id.split("_");
                                   ajaxRequest = new  htmldb_Get(
                                                 null,$v('APP_ID'),'APPLICATION_PROCESS=ORDER_PROCESS',0); 
                                   ajaxRequest.addParam('x01',$v(pThis));
                                   ajaxResponse = ajaxRequest.get();
                                  // new code
                                  // remove the alert once you are satisfied the process is running correct.
                                   alert(ajaxResponse);
                                   var vals = ajaxResponse.split(":"); 
                                  // $s(tid,ajaxResponse );
                                  $s("f05_"+tid[1],vals[0] );
                                  $s("f06_"+tid[1],vals[1] );
                                  $s("f07_"+tid[1],vals[2] );
                                }
                                </script>
                                There were errors in your OnDemand process. Not sure what it should , I just got rid of the errors.
                                declare
                                 px01 varchar2(100) := dbms_assert.enquote_literal(apex_application.g_x01);
                                 V_PLACE_FROM   varchar2(30);
                                 V_PLACE_TO   varchar2(30);
                                 V_DELIVERY_PRICE  NUMBER;
                                /*
                                 v_sql varchar2(1000) := 'select get_state_name(place_to) place_to_state,get_state_name(place_from) place_from_state,
                                place_to_id,DELIVERY_PRICE
                                */
                                 v_sql varchar2(1000) := 'select get_state_name(place_to_id) place_to_state,get_state_name(place_from) place_from_state,
                                DELIVERY_PRICE
                                from LOCATION_SHEET WHERE  LOCATION_ID = ';
                                begin
                                  v_sql := v_sql || px01;
                                   execute immediate v_sql into V_PLACE_FROM,V_PLACE_TO,V_DELIVERY_PRICE;
                                  htp.prn(V_PLACE_FROM||':'||V_PLACE_TO||':'||V_DELIVERY_PRICE);
                                exception
                                 when others then
                                   htp.prn(sqlerrm); 
                                   --NULL;
                                end;
                                WHEN OTHERS THEN NULL; is to be avoided at all times.
                                There is no place_to column in the LOCATION_SHEET table. Should it be place_to_id? I made that assumption.

                                Cheers,
                                • 13. Re: Multiple Values Tabular form
                                  695721
                                  now i create item called total , and i want to get sum value from DELIVERY_PRICE
                                  i make new dynamic action : total
                                  event :change
                                  selection type : jQuery selector
                                  input[name="f01"]
                                  action : event javascript code
                                  var total = 0;
                                  $('input[name="' + this.triggeringElement.name + '"]').each(function(){
                                    total+=parseInt(this.value);
                                  });
                                  $s('P2_TOTAL', total);
                                  but it's not get the sum (DELIVERY_PRICE)
                                  • 14. Re: Multiple Values Tabular form
                                    Prabodh
                                    Ahmed,
                                    You need to understand the code, blind copy paste is not the way to go.
                                    input[name="f01"]
                                    is wrong. That is the row selection item.
                                    It should be
                                    input[name="f07"]
                                    which is the price column.
                                    Moreover, your totaling must happen on f07, not f01.
                                    var total = 0;
                                    //$('input[name="' + this.triggeringElement.name + '"]').each(function(){
                                    $('input[name="f07"]').each(function(){
                                      if (this.value) { //Not null
                                        total+=parseInt(this.value);
                                      }
                                    });
                                    $s('P2_TOTAL', total);
                                    Check out your page now.