I've played with your code for hours and keep getting "Expecting an Object"
Grant Wagner wrote:[color=blue]
>
> Ed wrote:
>[color=green]
> > I need to know how to pass variables because I want to use the same
> > function to varify multiple data imput boxes.
> >
> > Please tell me what's wrong with this code.
> >
> > <head>
> > <script language="JavaScript">
> > function myFunction(this){[/color]
>
> "this" is a keyword representing the current object, it shouldn't and can't
> be used as a parameter name.
>
> Try
>
> function myFunction(referenceToAnInput) {
>[color=green]
> > entry=document.Forms[0].this.value;[/color]
>
> You've got a reference to the form element itself, it's unnecessary to
> reference the input this way. Simply use:
>
> var entry = referenceToAnInput.value;
>[color=green]
> > if (document.Forms[0].this.value==""){[/color]
>
> You store the input's value in a variable then you don't use it. If you're
> retrieving "entry", then make use of it:
>
> if (entry == "") {
>[color=green]
> > document.Forms[0].this.focus();[/color]
>
> referenceToAnInput.focus();
>[color=green]
> > }
> > else {
> > // Do something with "entry" here
> > }
> > if (this = "inputBox2") {[/color]
>
> if (referenceToAnInput.name == "inputBox2") {
>[color=green]
> > document.Forms[0].total.value = document.Forms[0].inputBox1.value
> > +document.Forms[0].inputBox2.value;[/color]
>
> var referenceToTheForm = referenceToAnInput.form;
> referenceToTheForm.total.value =
> parseFloat(referenceToTheForm.inputBox1.value) + parseFloat(entry);
>
> You need to parseFloat() because the values in input boxes are strings, if
> you simply added them together with "+", it would concatenate them, not add
> their numeric values (see <url:
http://jibbering.com/faq/#FAQ4_21 />)
>
> Since you retrieve "entry" at the beginning of the function, you might as
> well use it here rather then retrieving it again.
>[color=green]
> > }
> > }
> > </script>
> > </head>
> > <body>
> > <form>
> > <input type="text" name="inputBox1" onBlur="myFunction(this)">
> > <input type="text" name="inputBox2" onBlur="myFunction(this)">
> > <input type="text" name="total">
> > </form>
> > </body>[/color]
>
> Note that by using the onblur event, and putting focus back on the input
> when the input is invalid, you've trapped the user in that input until they
> enter something, and created a situation that could lead to an endless loop
> where they blur the input, you put the focus back on it, some other sequence
> of events blurs it again and so on.
>
> --
> | Grant Wagner <gwagner@agricoreunited.com>
>
> * Client-side Javascript and Netscape 4 DOM Reference available at:
> *
>
http://devedge.netscape.com/library/...ce/frames.html
>
> * Internet Explorer DOM Reference available at:
> *
>
http://msdn.microsoft.com/workshop/a...ence_entry.asp
>
> * Netscape 6/7 DOM Reference available at:
> *
http://www.mozilla.org/docs/dom/domref/
> * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
> *
http://www.mozilla.org/docs/web-deve...upgrade_2.html[/color]