Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Passing formname in the javascript function.

    Hi,
    I have one jsp page in which i am using dynamicform to create the forms.. I have 2 forms. I want to pass the formname to one javascript function and using that name i want to use the methods provided by that form.

    <code>
    isc.DynamicForm.create({
    ID: "temp",width: 300,height: 100,backgroundColor:"white",
    fields: [{ wrapTitle:false,name: "Id",width: "*",formItemType: "staticText", title: "userid",type: "text",
    }]
    });

    </code>

    i am passing this formname using this function ..
    <code>
    dochange('temp');
    </code>


    javascriptfile.js

    <code>
    dochange(){
    fname=arguments[0];

    uid=fname.getValue("id");
    alert(uid);
    }
    </code>

    i am not able to get the output .. it throws javascript exception that it doesn t support the method or property ...

    #2
    Note that in your dochange() method you are receiving a string holding the name of a form. Then you try to use this string as if it is a form instance. An easy change is to pass the form instance by removing the quotes from 'temp' which then references the global form object named temp.

    You get something like:
    Code:
    dochange(temp);
    
    dochange(form) {
        uid = form.getValue("id");
        alert(uid);
    }
    or you can eval() the string name to reference the form instance from name (not recommended):
    Code:
    dochange('temp');
    
    dochange(){
        fname=arguments[0];
    
        uid= eval(fname + ".getValue('id');");
        alert(uid);
    }
    Another option I believe will work is that each form is registered by its ID as global in the window[] object. So,
    Code:
    dochange('temp');
    
    dochange(){
        fname=arguments[0];
    
        uid= window[fname].getValue("id");
        alert(uid);
    }
    Be sure to match the parameter to getValue with the exact name used in defining the field (id vs Id).

    A good book on JavaScript might be in order.

    Comment


      #3
      thanks for the reply..

      Thanks for the reply...
      Originally posted by davidj6
      Note that in your dochange() method you are receiving a string holding the name of a form. Then you try to use this string as if it is a form instance. An easy change is to pass the form instance by removing the quotes from 'temp' which then references the global form object named temp.

      You get something like:
      Code:
      dochange(temp);
      
      dochange(form) {
          uid = form.getValue("id");
          alert(uid);
      }
      or you can eval() the string name to reference the form instance from name (not recommended):
      Code:
      dochange('temp');
      
      dochange(){
          fname=arguments[0];
      
          uid= eval(fname + ".getValue('id');");
          alert(uid);
      }
      Another option I believe will work is that each form is registered by its ID as global in the window[] object. So,
      Code:
      dochange('temp');
      
      dochange(){
          fname=arguments[0];
      
          uid= window[fname].getValue("id");
          alert(uid);
      }
      Be sure to match the parameter to getValue with the exact name used in defining the field (id vs Id).

      A good book on JavaScript might be in order.

      Comment

      Working...
      X