[thelist] form reference conundrum

Tom Dell'Aringa pixelmech at yahoo.com
Wed Jan 8 13:37:00 CST 2003


--- Chris Marsh <chris at webbtech.co.uk> wrote:
> Tom
>
> > I'm trying to access an element in my form to write a value
> > to it. I'm using the DOM lvl 0 as I always do, yet its not
> > working and it seems it should..maybe someone can point out my
> error.
> >
> > Here is the form:
> > --------------------
> > <form name="cartadd" method="POST" action="/preCart.php"
> > style="display: inline; height: auto;" onsubmit="track(this)">
> >
> > <input type="hidden" name="cust" value="">
> > //more elements
> > </form>
> > --------------------
> >
> > I want to access 'cust', the hidden element. I am doing this:
> >
> > -------------------
> > oForm = document.forms["cartadd"];
> > custHidden = oForm.elements["cust"]; <-- errors as null or not
> object
> > -------------------
> >
> > oForm returns an object for sure in an alert. 'cust' is
> > indeed the name of the element. There are no other forms on
> > this page named cartadd, nor any other form elements named
> > cust... I can't figure this out!
>
>>>>>>>>>>>>>>>>>>>>>>
I created a very simple html page containing only the form
information, and a function called Test() which contained the
javascript alerting the value of custHidden. The test function was
executed upon clicking a link in the HTML. This behaved as one would
expect, displaying [object] in the alert. Are you executing the
javascript *after* the page has loaded? If the javascript is inline,
then the field will not necessarily exist at runtime.
>>>>>>>>>>>>>>>>>>>>>>>

I'm trying to do it using the onLoad() handler. So the element should
be there!

When I check this in NS6.2 - I DO NOT get an error on that. If I
enter:

document.forms["cartadd"].elements["cust"]

into the JS console for evaluation, I get this error:

"Error: document.forms.cartadd has no properties"

I can get this using getElementById() and it will work, but that
screws me for some browsers..any ideas? Here is the full form:

----------------------
<td class="line">
<form name="cartadd" method="POST" action="/preCart.php"
style="display: inline; height: auto;" onsubmit="track(this)">
<input type="hidden" name="cust" value="">
<input type='hidden' name='uid' value="<?=$uid?>">
<input type='hidden' name='smode' value="add">
<input type="hidden" name="product_no" value="<?=$pid?>">
<input type='hidden' name='start' value="1">
<input type='hidden' name='total' value="25">
<input type='hidden' name='searchpath' value="d10a8f84f260c8d20fc1">
<input type='hidden' name='search'
value="&category=Besamim+%28Spice%29+Containers">
<span class="add">Quantity&nbsp;</span><input type="text" name="qty"
value="1" size="3" class="add" /><br /><input type="submit"
value="Add To Shopping Cart" class="add" /></form></td>
-------------------------

Tom


=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list