We help IT Professionals succeed at work.

I'm getting an object expected

This code gives me an object expected once I fill in the x_Amount field. What am I doing wrong?
<input type="text" name="x_Amount" size="10" onChange="fixField();">
          <script type="text/javascript">
                  function fixField()
                  {
                  var = amount;
                  amount=document.Add.x_Amount.value;
                  document.write('<input type=hidden name=Products size=10 value=' + amount + '::1::001::donation::{TEST}{TESTD}{RB}>');
                  }
            </script>
Comment
Watch Question

Chinmay PatelChief Technology Ninja
Distinguished Expert 2019

Commented:
Hi go2gvc,
did you try to debug your script? by putting debugger; at the beginning of your function?
Also looks like document.Add.x_amount.value will not work as it is. Do you have a form named Add?
Also I suggest you use document,getElementById("x_Amount") .value instead of document.Add.
Regards,
Chinmay


Author

Commented:
I tried this but I'm still getting the same error with no break in the script. The error doesn't occur until I actually enter an amout and click off the field.
<input type="text" name="x_Amount" id="x_Amount" size="10" onChange="fixField();">
          <script type="text/javascript">
                  function fixField()
                  {
                  debugger;
                  var = amount;
                  amount=document.getElementById("x_Amount").value;
                  document.getElementById("Products").value=amount + "::1::001::donation::{TEST}{TESTD}{RB}";
                  }
            </script>
            <input type="hidden" name="Products" id="Products" size="10" value="">
Chinmay PatelChief Technology Ninja
Distinguished Expert 2019

Commented:
Which debugger your are using? also tell me which browser you are using?
it should actually be

amount=document.forms[0].Add.x_Amount.value;

since Add.x_Amount is a name not an id

Author

Commented:
I've figured it out. Thank you.