473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

function w/ parameter

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>
Jul 23 '05 #1
3 1301
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
Jul 23 '05 #2
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>

Jul 23 '05 #3
Mick / Rob,

Thanks. Excellent explanations. Everything is working correctly.

"danny" <dt*****@planet-inc.net> wrote in message
news:11*************@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>

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
14
by: dover | last post by:
/*Copy the line a token at a time into the output*/ copy(istream_iterator<string>(iss), istream_iterator<string>(), ostream_iterator<string>(oss, " ")); What's the meaning of this statement?...
4
by: Vish | last post by:
Hi all, I am having a build error in one of the overloaded functions in my class. The function takes either a string as a parameter or a type referenced in another dll as a parameter. My class...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
5
by: pauldepstein | last post by:
Hi all, I saw some code like this: unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const SomeClass& SomeMem, bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned...
1
by: Jorge | last post by:
On Oct 23, 10:36 am, Tuxedo <tux...@mailinator.comwrote: Yes: function first_function (PARAMETER) { preload_image = new Image(800,600); preload_image.onload = function () {...
10
by: Constantine AI | last post by:
Hi i am having a little problem with an equation function that was created from all your help previously. The function works fine itself but with a small glitch within it. Here is the function...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.