List Info

Thread: Re: assigning value from one field to another




Re: assigning value from one field to another
country flaguser name
Sweden
2008-03-26 02:11:27


> Re: assigning value from one field to another
> Posted by: "venkat pingala" reddy.pingala4%40gmail.com">reddy.pingala4gmail.com
> Date: Tue Mar 25, 2008 1:29 pm ((PDT))
>
> Hi David,
>
> I have corrected the code to work, please check it once and let me know if u
> have any problems.

It works, but it still contains errors.

>
> <html&gt;
> <head&gt;
> <script language=&quot;javascript">
> function CreateOrderString(form) {
> var amount = document.OrderForm.chargeamount.value ;
> document.OrderForm.orderstring.value = "1~Dummy Order String~&quot; + amount
&gt; +"~1~N~||" ;
> document.OrderForm.orderstring.focus();

If you pass "this.form" to the event handler function (see below), then you can
replace "document.OrderForm" with "form" whever it occurs in this function.

> return true;

Not needed. You only need to return true or false if the function is called by
submitting the form. But this function isn't called by an onsubmit handler, it's
called using an onchange handler.

> }
> </script>
>; </head&gt;
> <body&gt;
> <form name=";OrderForm&quot;>
> <input type=";text" name=";chargeamount" size=";15" onChange=&quot;return
> CreateOrderString(this)" >

"this&quot; mean "the current object or element&quot;; here, it refers to the *input*, not
to the form. Use "this.form" to refer to the form which contains the input.

Also, you've no need to return a value, because the function already does the
work of updating the value of orderstring.

So the event handler can be written like this:

onchange=&quot;CreateOrderString(this.form);"

---

Another alternative is to use "CreateOrderString(this);&quot; in the event handler
and then write the function itself like so:

function CreateOrderString(input) { // "this" in event handler
// ->> input object passed to function
var myForm = input.form; // myForm = form containing the input
var amount = myForm.chargeamount.value ;
myForm.orderstring.value = "1~Dummy Order String~&quot; + amount
+"~1~N~||" ;
myForm.orderstring.focus();
}

---

cheers

jon.

> <input type=";text" name=";orderstring" size=";60" value=&quot;">;
> <input type=";submit&quot; value=&quot;submit&quot;>
> </form&gt;
> </body&gt;
> </html&gt;
>
> Regards,
> Venkat

--
This message has not been scanned for viruses.

Since I do not use a Microsoft operating
system or software, and use only plaintext
for email, there is little need for me to do so.

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )