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 37732 articles. 15 followers. Post

3 Replies
166 Views

Similar Articles

[PageSpeed] 19

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

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...