> This looks like it should work except for the quotes around the passed
> parameter variable "control", won't it take that as a string literal
[quoted text clipped - 3 lines]
> get errors. I am confused on how to reference variables correctly in
> this model. Thanks, john
Whoops! Heh. Good catch. Yes, that should be
document.forms["Form1"].elements[control]
You say you've tried it like that and still are having trouble? The
control parameter should be a string (literal or variable) that contains
the name of the form element you want to validate. So, this should work
with your function:
<form name="Form1">
<input name="Field1">
<button onclick="validateNumeric('Field1');">Validate</button>
</form>
-ivan.
bruce barker - 12 Mar 2004 01:48 GMT
its simpler and cleaner if you just pass the control:
<form name="Form1">
<input name="Field1">
<button onclick="validateNumeric(this);">Validate</button>
</form>
<script>
function validateNumeric(oControl)
{
if(isNaN(oControl.value))
{
alert("This field represents a money value and must be numeric.");
oControl.focus();
oControl.select();
}
}
</script>
-- bruce (sqlwork.com)
> > This looks like it should work except for the quotes around the passed
> > parameter variable "control", won't it take that as a string literal
[quoted text clipped - 19 lines]
>
> -ivan.
Randy Webb - 12 Mar 2004 05:25 GMT
> its simpler and cleaner if you just pass the control:
>
[quoted text clipped - 14 lines]
> }
> </script>
"this", in that context, refers to the button, not the input. So the
function is checking to see if the buttons value is a number, if its not
then you get the alert.

Signature
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
bruce barker - 12 Mar 2004 17:24 GMT
you're right, i should have looked what the code was doing closer. a more
common approach whould be:
<form name="Form1">
<input name="Field1" onblur="validateNumeric(this);">
</form>
<script>
function validateNumeric(oControl)
{
if(isNaN(oControl.value))
{
alert("This field represents a money value and must be numeric.");
oControl.focus();
oControl.select();
}
}
</script>
-- bruce (sqlwork.com)
> > its simpler and cleaner if you just pass the control:
> >
[quoted text clipped - 23 lines]
> Chance Favors The Prepared Mind
> comp.lang.javascript FAQ - http://jibbering.com/faq/
Dave Anderson - 12 Mar 2004 18:20 GMT
> its simpler and cleaner if you just pass the control:
>
> <form name="Form1">
> <input name="Field1">
> <button onclick="validateNumeric(this);">Validate</button>
> </form>
An alternative correction to "this" example:
<BUTTON ONCLICK="validateNumeric(this.form.Field1)" ...

Signature
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.