From: vikesfan on
I have the following code in my page:

function formSubmit(next){
document.forms[0].button.value = next;
document.forms[0].userAgent.value = navigator.userAgent;
document.forms[0].submit();
}


When I hit the submit button which runs this code none of the form
fields are populated. when I try to pull them out in my Java code they
are empty. Any idaes? Thanks.

From: vikesfan on
Thought I'd add that this works on safari versions 1.3.1 thru 3 and
2.0.1.

From: Thomas 'PointedEars' Lahn on
vikesfan wrote:

> I have the following code in my page:
>
> function formSubmit(next){
> document.forms[0].button.value = next;
> document.forms[0].userAgent.value = navigator.userAgent;
> document.forms[0].submit();
> }
>
>
> When I hit the submit button which runs this code none of the form
> fields are populated. [...]

"Does not work" is a useless error description. [psf 4.11]

Read the FAQ, especially <URL:http://jibbering.com/faq/#FAQ4_43> and
try the standards compliant approach:

document.forms[0].elements['button'].value = next;
document.forms[0].elements['userAgent'].value = navigator.userAgent;

It also is highly likely that you have a control named `submit' which
overrides/overwrites the submit() method. In that case you should see a
TypeError exception ("submit is not a function") on the submit() line.


HTH

PointedEars
From: Randy Webb on
Thomas 'PointedEars' Lahn said the following on 3/11/2006 5:18 PM:
> vikesfan wrote:
>
>> I have the following code in my page:
>>
>> function formSubmit(next){
>> document.forms[0].button.value = next;
>> document.forms[0].userAgent.value = navigator.userAgent;
>> document.forms[0].submit();
>> }
>>
>>
>> When I hit the submit button which runs this code none of the form
>> fields are populated. [...]
>
> "Does not work" is a useless error description. [psf 4.11]

Then it's a good thing he didn't say that then, huh?

> Read the FAQ, especially <URL:http://jibbering.com/faq/#FAQ4_43> and
> try the standards compliant approach:
>
> document.forms[0].elements['button'].value = next;
> document.forms[0].elements['userAgent'].value = navigator.userAgent;

There is nothing more "standards compliant" about what you posted than
what the OP posted. Both are equally "compliant". If want to nit-pick it
into compliance, then don't mix numeric indexes and string indexes:

document.forms['formID'].elements['userAgent'].value;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
From: Lasse Reichstein Nielsen on
Randy Webb <HikksNotAtHome(a)aol.com> writes:

> Thomas 'PointedEars' Lahn said the following on 3/11/2006 5:18 PM:
>> vikesfan wrote:
>>> document.forms[0].button.value = next;

>> document.forms[0].elements['button'].value = next;

> There is nothing more "standards compliant" about what you posted than
> what the OP posted. Both are equally "compliant".

No need to put "compliant" in quotes[1].

The specification is not entirely clear on this point. There is no
doubt that what Thomas Lahn wrote is only relying on features
standardized by the W3C HTML DOM (even in version 1) ECMAScript
bindings.

There is doubt that the named controls should be made available as
properties of the form element itself, and not just as properties of
the elements collection. Doing so is unnecessary (since the elements
collection is specified) and it is likely to lead to name collisions
between form controls and properties and methods of the form
element. It is, however, what most brosers have done, leading
to the recurring problem of "form.submit() doesn't work .. oh, the
submit button is named 'submit'".

/L
[1] Damn, now I did it!
--
Lasse Reichstein Nielsen - lrn(a)hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 |  Next  |  Last
Pages: 1 2
Prev: DOM for IE and Firefox
Next: window.open and focus