how to write an action in javascript function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msg2ajay
    New Member
    • Jun 2007
    • 17

    how to write an action in javascript function

    hi,
    Below getRimData() is a function which will call .js file. It is included in
    Code:
    <html:select property="lbrokercd"  value="" [B]onchange="document.forms[0], '/ILICTreasury/banker-web/X32.do', this, 'IX3201')"[/B]>
    ---------> IT IS WROKING WELL

    <head>
    Code:
    function doAction(){
    getRimData(document.forms[0], '/ILICTreasury/banker-web/X32.do', 
                   this, 'IX3201');
            }
    </head>
    <body>
    
    <html:select property="lbrokercd"  value="" [B]onchange="doAction()"[/B] ----------> it is not calling getRimData ();
    <body>
    when ever the "doAction" is called it should execute the function "getRimData()". . but it is showing some error.


    thx
    HAN
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    at least you have to pass the this-variable to your function because getRimData awaits it:

    Code:
    onchange="doAction(this);"
    kind regards

    Comment

    • msg2ajay
      New Member
      • Jun 2007
      • 17

      #3
      hi,
      i have alerady passed the 'this' in that but i am getting same error again



      hi,

      while copying from my page it just not copied.... the code is like this....
      <html:select property="lbrok ercd" value="" onchange="doAct ion()"/>

      My question is how to call a method inside a javascript function?.Acuta lly my idea is as below.


      Code:
      <html>
      <head>
         <script language="javascript" src="../../js/module.js"></script>
         <script language="javascript">
            function domyAction(){
                     onemoreAction('arg1','arg2','arg3','arg4'); //-------> this described in .js file    
              }
               </script>
      </head>
      <body>
      <select onchange="domyAction()">
        <option value ="volvo">Volvo</option>
        <option value ="saab">Saab</option>
        <option value ="opel">Opel</option>
        <option value ="audi">Audi</option>
      </select>
      </body>
      </html>





      thx,
      Ajay

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        hi ...

        i cannot see where you pass the this to your doAction-function ... however: have a look at the following example:

        [CODE=javascript]
        <html>
        <head>
        <script type="text/javascript">

        function test(val) {
        alert(val);
        }

        function domyAction(obj) {
        test(obj.value) ;
        }

        </script>
        </head>
        <body>
        <select onchange="domyA ction(this)">
        <option value ="volvo">Vol vo</option>
        <option value ="saab">Saab </option>
        <option value ="opel">Opel </option>
        <option value ="audi">Audi </option>
        </select>
        </body>
        </html>
        [/CODE]
        kind regards

        Comment

        • msg2ajay
          New Member
          • Jun 2007
          • 17

          #5
          i am giving tow code's of two files.
          Case1,Case 2
          in case1 my code is working fine but not working in case2... why?
          In Case1 i placed my function getRimData() in 'onChange()',
          bue in Case 2 i place in javascript function. what is the difference?



          Code:
          case 1:--->html:select onChange one javascript method is calling and it is wroking fine but i want, like case2:
          
          case1:
          ------
          <body>
           <html:select property="lbrokercd" styleClass="dropdown" value="${X32.lbrokercd}" onchange="getRimData(document.forms[0],'/ILICTreasury/banker-web/X32.do',this, 'IX3202');">
                 <html:option value="">Please Select</html:option>
                 <html:option value="1">1- HIDRO</html:option>
                 <html:option value="2">2- BI-HIDRO</html:option>
                 <html:option value="3">3- DI-HIDRO</html:option>
                 <html:option value="4">4- N-HIDRO</html:option>
          </html:select>
          
          </body>
          
          
          --------------------------------------------------------------------------------------------------
          
          
          
          case2:
          
          <script>
          
                 function doAction(){
                          getRimData(document.forms[0],'/ILICTreasury/banker-web/X32.do',this, 'IX3202');
                  }
          
          </script>
          
          <body>
           <html:select property="lbrokercd" styleClass="dropdown" value="${X32.lbrokercd}" onchange="doAction()">
                 <html:option value="">Please Select</html:option>
                 <html:option value="1">1- HIDRO</html:option>
                 <html:option value="2">2- BI-HIDRO</html:option>
                 <html:option value="3">3- DI-HIDRO</html:option>
                 <html:option value="4">4- N-HIDRO</html:option>
          </html:select>
          
          </body>

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            as i said ... have a look at the this-keyword ... it is a reference to the actual object in your case and you don't pass it to the doAction() function so getRimData() has another this as it needs!!!!! pass 'this' from the onchange to getRimData through the entire chain of calls! try the following:

            [HTML]<script>
            function doAction(obj) {
            getRimData(
            document.forms[0],
            '/ILICTreasury/banker-web/X32.do',
            obj,
            'IX3202'
            );
            }
            </script>
            <body>
            <html:select property="lbrok ercd" styleClass="dro pdown"
            value="${X32.lb rokercd}" onchange="doAct ion(this)">
            <html:option value="">Please Select</html:option>
            <html:option value="1">1- HIDRO</html:option>
            <html:option value="2">2- BI-HIDRO</html:option>
            <html:option value="3">3- DI-HIDRO</html:option>
            <html:option value="4">4- N-HIDRO</html:option>
            </html:select>
            </body>
            [/HTML]

            kind regards

            Comment

            Working...