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