function w/ parameter

  • Permalink
  • submit to reddit
  • Email
  • Follow


I have a function that when uses the form name works correctly. Should I
pass a variable to the function using either BizReset('bizform') or
BizReset(getElementById('bizform') statements I receive the error
"elements.length is either null or an object".
Any Suggestions?

<script = "text/javascript>
function BizReset(curform) {
    len = curform.elements.length;
 var blank = ""
 for(i=0;i<len;i++) {
   if (curform.elements[i].type == "text") {
     curform.elements[i].value = blank;
     curform.elements[i].disabled=false;
   }
 }
   QuoteLayerOn(0);
   DisplayButtons(0);
   document.curform.BizName.focus();
}
</script>


0
Reply dthomas (7) 3/4/2005 10:43:38 AM

See related articles to this posting


danny wrote:
> I have a function that when uses the form name works correctly. Should I
> pass a variable to the function using either BizReset('bizform') or

  Please hang in there, there's quite a bit to talk about here...

  This method of calling your function is incompatible with the
  code you have posted.  If you pass the name of the form as a
  string (as above), use:

  function BizReset(curform) {
    var f = document.forms[curform];
    // now do things with f

> BizReset(getElementById('bizform') statements I receive the error

If you are going to reference your form this way, you must put an 
id on the form 'bizform' and fix the syntax error.

   <form id="bizform" ... >
   ...

   ... onclick="BizReset(getElementById('bizform'));" ...
   ...

   function BizReset(curform) {
     // curform will be a reference to the form
     var len = curform.elements.length;
     ...

> "elements.length is either null or an object".
> Any Suggestions?
> 
> <script = "text/javascript>

   <script type="text/javascript">

> function BizReset(curform) {
>     len = curform.elements.length;

  Unless 'len' needs to be global, keep it local:

       var len = curform.elements.length;

>  var blank = ""
>  for(i=0;i<len;i++) {

  Same with 'i'

    for(var i=0; i<len; i++) {


>    if (curform.elements[i].type == "text") {
>      curform.elements[i].value = blank;

  The variable 'blank' is not needed, you could just write:

        curform.elements[i].value = '';

>      curform.elements[i].disabled=false;
>    }
>  }
>    QuoteLayerOn(0);
>    DisplayButtons(0);

  If these are not part of your problem, remove them for the sake
  if fixing your error.

>    document.curform.BizName.focus();

  You should check that the focus method is supported first (e.g.
  older versions of Safari don't).  And curform is a reference to
  the form, so 'document.' will cause an error:

  if (curform.BizName.focus) curform.BizName.focus();

> }
> </script>
> 
> 

  Here is a modified version of your form that shows different ways
  to do what I think you are trying to do.

<script type="text/javascript">
// Pass a reference to the form
function BizResetA(curform) {
  var len = curform.elements.length;
  for(var i=0;i<len;i++) {
    if (curform.elements[i].type == "text") {
      curform.elements[i].value = '';
      curform.elements[i].disabled=false;
    }
  }
  if (curform.BizName.focus) curform.BizName.focus();
}

// Pass the name of the form as a string
function BizResetB(curform) {
  var f = document.forms[curform];
  var len = f.elements.length;

  for(var i=0;i<len;i++) {
    if (f.elements[i].type == "text") {
      f.elements[i].value    = '';
      f.elements[i].disabled = false;
    }
  }
  if (f.BizName.focus) f.BizName.focus();
}

</script>
<form action="" name="BizForm">
   <input type="text" name="BizName" value="something" disabled>
   <input type="button" onclick="
     BizResetA(this.form);" value="this.form">
   <input type="button" onclick="
     BizResetB('BizForm');" value="'BizName'">
   <input type="reset">
</form>


-- 
Rob
0
Reply RobG 3/4/2005 2:05:36 PM

danny wrote:

> I have a function that when uses the form name works correctly. Should I
> pass a variable to the function using either BizReset('bizform') or
> BizReset(getElementById('bizform') statements I receive the error
> "elements.length is either null or an object".
> Any Suggestions?
> 

BizReset(document.getElementById('bizform'));
or better:
BizReset(document.forms['bizform']);

Mick


> <script = "text/javascript>
> function BizReset(curform) {
>     len = curform.elements.length;
>  var blank = ""
>  for(i=0;i<len;i++) {
>    if (curform.elements[i].type == "text") {
>      curform.elements[i].value = blank;
>      curform.elements[i].disabled=false;
>    }
>  }
>    QuoteLayerOn(0);
>    DisplayButtons(0);
>    document.curform.BizName.focus();
> }
> </script>
> 
> 
0
Reply Mick 3/4/2005 3:42:19 PM

Mick / Rob,

Thanks.  Excellent explanations. Everything is working correctly.

"danny" <dthomas@planet-inc.net> wrote in message
news:112gf086kk14571@corp.supernews.com...
> I have a function that when uses the form name works correctly. Should I
> pass a variable to the function using either BizReset('bizform') or
> BizReset(getElementById('bizform') statements I receive the error
> "elements.length is either null or an object".
> Any Suggestions?
>
> <script = "text/javascript>
> function BizReset(curform) {
>     len = curform.elements.length;
>  var blank = ""
>  for(i=0;i<len;i++) {
>    if (curform.elements[i].type == "text") {
>      curform.elements[i].value = blank;
>      curform.elements[i].disabled=false;
>    }
>  }
>    QuoteLayerOn(0);
>    DisplayButtons(0);
>    document.curform.BizName.focus();
> }
> </script>
>
>


0
Reply danny 3/4/2005 5:28:18 PM
comp.lang.javascript 37857 articles. 16 followers. Post

3 Replies
224 Views

Similar Articles

[PageSpeed] 52


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Define PostgreSQL Function (View w/ Parameters) in DCT
In PostgreSQL, a view requiring parameters gets defined as a function that returns a table. Has anyone successfully defined this type of return table in a Clarion DCT? I get a file open error but believe the table name variable must be set to something like - MyPGFunctionName(INT,INT) - in order to be recognized in PostgreSQL. On 17/05/14 05:26, Douglas Johnson wrote: > In PostgreSQL, a view requiring parameters gets defined as a function that returns a table. Has anyone successfully defined this type of return table in a Clarion DCT? > > I get a file open error but believe ...

How to create a function that makes a .txt file w/ file name as parameter
Hello folks, in need of a little help. I'm trying to construct a function that would create datapoints according to some equations and rules I've entered & parameters that are given by user. Everything works fine, but with the current code I can only make a file "testdata.txt". I'd like to change this so that the user could give the desired file name as an input parameter. How on earth can I do this? Current code is: function z=CreateTPs(Form,R,maxstress,minstress,totalN,kNperV,c) %(blablabla) fid = fopen('testdata.txt', 'w'); fprintf(fid,...

Function as parameter of a function with parameters
Hello, I can do : void DoFunct(void (*funcp)()); void MyFunct() { //... } DoFunct(MyFunct); but is it possible to pass to DoFunct() a function MyFunct with parameters ? Thanks in advance. marc wrote: > Hello, > > I can do : > > void DoFunct(void (*funcp)()); > > void MyFunct() > { > //... > } > > DoFunct(MyFunct); > > but is it possible to pass to DoFunct() a function MyFunct with > parameters ? > > Thanks in advance. void DoFunct(void(*funcp)(int)); void MyFunct(int i) { // ... } int main(void) { DoFunct(MyFunct); // ... ...

How to pass a parameter for a function parameter in a function
function foo(msg) { alert(msg); } var insertForm = function() { this.button = $('add_customer'); this.button.observe('click', foo('hello world')); } The above line ' this.button.observe('click', foo('hello world'));' does not really work. It will work if I don't pass any parameters. AzamSharp a �crit : > function foo(msg) > { > alert(msg); > } > > > > var insertForm = function() > { > this.button = $('add_customer'); > this.button.observe('click', foo('hello ...

restriction of a two-parameters function to a one-parameter function
Hi, suppose we have these two functions (not very interesting, but this is for clarity) : -) a function Primitive that computes at t the primitive of a function f : double Primitive ( double(*f)(double), t); -) a function Indicatrice that defines if the parameter t is in the interval [i, i+1] : double Indicatrice ( int, double ); I'd like to write a function Indicatrice_i, restriction of Indicatrice to i, like this : double (*Indicatrice_i)(double) = Indicatrice(i); to use it such this manner : ...

Functions as function parameter
Hi, I want to pass a C-function as a function parameter but I don't know how to that correctly. In the example below how would I have to declare the function argument in the my_sort function definition? Thank you in advance for any help. Regards Rolf int comp_func1(double * a1, double * a2) { ... } void my_qsort(double * a, int n, (* comp_func)) { ??????? ... comp_func(&a[i], &a[j]); ... } int main() { ... my_qsort(a,n,comp_func1); } Rolf Wester <rolf.wester@ilt.fraunhofer.de> scribbled the following: > Hi, > I want to ...

function with parameters of function
Hi there, I'm studying dynamic data structure (simple & double linked list, heap, cola, tree, etc) but the teacher obviated the namespaces and others declarations that I don't know their names, old students call it demons inside functions. I'm writing here hoping for you can help me. I've downloaded a tuto where is explained what are the namespace, so, I don't have doubts about it. The other thing is something like a function with parameters of function (called demons), here, I write you the classes declaration that he wrote on the blackboard, unfortunately he didn&#...

defining a function whose parameter must be a function with two parameters
Dear all, I am trying to define a function F which will only execute if its parameter is a function with two parameters. Let's say I define it thus, without any checks on the parameter pattern f: In[1] := F[f_] := f[2,3] There are several ways of calling F: 1) pass it a function of two parameters: In[2] := F[Function[{a,b},a^2-b^2]] Out[2] = -5 2) pass it an anonymous function of two parameters: In[3] := F[#1^2-#2^2 &] Out[3] = -5 3) pass it a pre-defined function: In[4] := g[a_,b_] = a^2-b^2; In[5] := F[g] Out[5] = -5 My question is: how can I define a pattern ...

Given function of single parameter function, to find function and
By what Mathematica procedures is it possible to solve for function f and the parameter/argument linking relation UV [u,v] = 0 from a given relation f[v]= 4 f[u]^3 - 3 f[u] ? Known answer for this case is function f = cos, argument link relation v =3 u respectively. For another simpler case f(u)^2 + f(v)^2 =1, one solution is u + v = (2 k-1) pi/2, for f = cos or sin. Best Regards Narasimham ...

How to pass a function pointer to a function with std::function parameters
{ Reformatted; please limit your lines to 70 characters -mod } Hi, I am trying to write a little helper template function which takes a std::function object and a parameter and calls the function object and does some additional work. This all works fine until I try to call the template function with a function pointer directly without first creating a temporary std::function object: #include <functional> void globalF(int) { } struct A { void memberF(int); }; template<typename T> void call(std::function<void (A*, T)> func, T x) { A a; fu...

function pointers as function parameters
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints the return value of ff(). The code below seems to work, but I would appreciate your comments. Have I got it right? Does the function name "decay" to a pointer? #include <stdio.h> /* declares a function which takes an argument that is a pointer to a function returning an int */ void f(int (*fptr)()); /* function returning an int */ int ff(void); int main(void) { f(ff); ...

m-function with function parameter
How to write a matlab function which its parameter is a function? thanks a lot! su flora wrote: > > > How to write a matlab function which its > parameter is a function? > thanks a lot! Read the help entry Programming and Data Types: Function Handles / per ...

mapping functions with functions as parameters?
Hi! does anybody know how to use a mapping function with functions instead of lists? I've written some auxiliary functions and instead of calling them separately with many conditions I want to use a mapping function like that: (map #' (lambda (i) (do-something)) '(test1 test2 test3 test4)) My code looks like: (test1) (when (=T found-nothing) (test2) (when (=T found-nothing) (test3).... Thanks! Daniela In article <1174979567.153752.98330@d57g2000hsg.googlegroups.com>, Daniela.Nitsch@web.de wrote: > Hi! > > does anybody know how to use a mappi...

Function pointer as function parameter
I've developed an application using both Fortran and C languages. Fortran layer is the upper layer and uses C functions to perform low level operations. I need to supply a Fortran function to a C function as parameter (C function has a pointer to function as parameter) in order to let the C function call the Fortran one. It creates me some problems... function pointer is not correctly passed to C function... Can someone give me some advice to solve this problem ??? // This is the fortran call where createthread is the C function and proc_x_dsv2 is the fortran function supplied as param...

template function as function parameter
Hi all, I was wondering if anyone had dealt with a similar problem. I need to use a template function as the parameter for a particular function (also template function). The program compiles into an object file but then at the final stage it says that it can't find template function. The platform is WindowsXP Pro, MSCV++ ..Net. More specifically what I want to do is write an atl algorithm that will also accept another algorithm as a function parameter. This is inteface of the outer algorithm: template <class iterator, class outiterator, class Alg> void transform_slide ( itera...

write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter.and no of parameter is calling function can be anything. for example.suppose my function is function2. then when i call function1(int i ,char j,float d) { function2() } ouput should be i is integer j is char d is float and data type can be anything On 24 Jan 2005 20:47:35 -0800, "komal" <avinash.gangwal@gmail.com> wrote: >hi all >basically my problem is i have to write a func...

Change function parameter from inside the function
Hi, Is there a way to change a parameter to a function in the body of the function? For instance, I have this function (defun add-to-population (rs1 population) (adjoin rs1 population :test #'equal) ) That I use this way (setq current-population (add-to-population result current-population)) But since I always use this same form (return a value, and then use setq to assign this return value to the function parameter), I would like to do this operation this way: (add-to-population result current-population) Basically, whatever is passed as the population argument should be assigne...

Passing parameter to function not expecting parameter
I have come across some code that has been working for years, in which function A calls function B and passes a parameter, but function B does not expect any parameters! (Obviously there was no prototype for B, an oversight which is being corrected. With full warnings on, gcc warns of "implicit declaration" which was the clue). Anyway, my question is: what type of problems might this have been causing? I know, I know, you'll tell me nasal daemons and anything at all etc etc, but thnking about some typical implementations, might there be some data hanging around on ...

pass function into another function as parameter?
hi, is it possible to pass a function into another function as a parameter? Say i have these: function SaveMe(text) {...} function SaveMeNow(text) {...} function WhichToSave(x, y, z) {...} a button will call WhichToSave, that function will perform some logic and then call one of the Save methods, can i pass that method in as say parameter z and have it just call the function right away, passing one of the SaveMe methods a parameter which is determined by the WhichToSave method? Thanks. On Nov 20, 3:57=A0pm, soni2926 <soni2...@yahoo.com> wrote: > hi, > is it possible to pass ...

Function pointer array as parameter to a function
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure about the syntax of calling the same. #include <stdio.h> void fp1() { printf("In fp1\n"); } void fp2() { printf("In fp2\n");} void fp3() { printf("In fp3\n");} void call_fpn(void (*fp[3])()) { (*fp[0])(); (*fp[1])(); (*fp[2])(); } void main() { void (*pfn[3])()={NULL}; pfn[0]=&fp1; pfn[1]=&fp2; pfn[2]=&fp3; call_fpn(.....); } Can som...

Multiple parameter packs in function parameters
Is this valid code, or should it even compile? template<typename... Pack1, typename... Pack2> void func(Pack1... pack1, Pack2... pack2) {} Currently the behavior of that seems quite erratic in different compilers. In gcc you can t call that with zero arguments, but you can call it with at least one argument (such as "func(5);") All the parameters are passed as 'pack2'. With clang if you try to call it directly with "func()" or "func(5)" you get strange and conflicting error messages (in the first case it tells that 'func&...

help:how to create a function with function handle parameter?
hi, guys, I want to pass a function handler into another function but matlab keeps telling me there is a mistake. I guess it does not recognize the parameter as a function handler rather than a ordinary variable. Here is my code: function result=testfunctionhandle() result=ope(@add,3,5); function result=ope(funfcn,x,y) result=funfcn(x,y); function r=add(x,y) r=x+y; The error message returned from matlab: ??? Index exceeds matrix dimensions. Error in ==> testfunctionhandle.m (ope) On line 8 ==> result=funfcn(x,y); Error in testfunctionhandle.m On line 4 ==> result=ope(@add,3...

Are default function parameters in allowed in function templates?
I know that default template arguments cannot be used in function templates but are default function parameters legal? That is, is this: ---------------------------------- #include <functional> template<class T, class C> bool count(T x[], C cmp = std::less<T>()) { for(int i = 0; i < 9; ++i) if(cmp([i], x[i + 1])) return true; return false; } ---------------------------------- legal C++ code? count(x, std::less<int>()); // compiles ok, but count(x); // gives "could not deduce template argument for 'C'" Brian Gladman ...

passing S-function parameters from an external function
Hello, I have an .mdl file with an S-function inside. The S-function needs additional parameters passed externally. When running from the Simulink window or thru .m script (using sim), there is no problem. But when running from an external .m function (using sim), my additional parameters are out of scope, so I get an error message. What can I do to pass these parameters to my S-function? Thank you, Israel Zadok. ...