form submit problem

M

Martin Nadoll

Hello,

i try to submit a form with textlink like this snippet:

<a href="javascript:document.bestellen.submit()">bestellen</a>
<form name="bestellen" method="post"
action="myPage.cfm?ID=4300&do=action">
<input name="category" type="hidden" value="2">
<input name="Product" type="hidden" value="423">
<input name="Price" type="hidden" value="15">
<input name="action" type="hidden" value="basket">
<input name="Quantity" type="hidden" id="Quantity" value="1">
</form>

but this results in a javascript error: this object dont use that method (or
something, its in german).

Where am i wrong here?


Thanks for any help,
Martin Nadoll
 
D

Dennis Biletsky

Martin Nadoll said:
Hello,

i try to submit a form with textlink like this snippet:

<a href="javascript:document.bestellen.submit()">bestellen</a>
<form name="bestellen" method="post"
action="myPage.cfm?ID=4300&do=action">
<input name="category" type="hidden" value="2">
<input name="Product" type="hidden" value="423">
<input name="Price" type="hidden" value="15">
<input name="action" type="hidden" value="basket">
<input name="Quantity" type="hidden" id="Quantity" value="1">
</form>

but this results in a javascript error: this object dont use that method (or
something, its in german).

Where am i wrong here?


Thanks for any help,
Martin Nadoll

I have checked this piece of code in Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8 and MSIE
6.0.2800.xpclnt_qfe.021108-2107 and it works fine in both.
 
T

Thomas 'PointedEars' Lahn

Martin said:
i try to submit a form with textlink like this snippet:

<a href="javascript:document.bestellen.submit()">bestellen</a>

That's nonsense. "javascript:" is nonsense (see the FAQ) and nobody
can order without support for client-side scripting, although that would
not be necessary. Besides, the standards compliant reference would be

document.forms['bestellen'].submit();

If you have still problems with this, maybe the cause is that the "form"
element is located *after* the "link" or you may have tested with IE and
slided on the shared namespace of variables and element names/IDs in its DOM.
<form name="bestellen" method="post"
action="myPage.cfm?ID=4300&do=action">
<input name="category" type="hidden" value="2">
<input name="Product" type="hidden" value="423">
<input name="Price" type="hidden" value="15">
<input name="action" type="hidden" value="basket">
<input name="Quantity" type="hidden" id="Quantity" value="1">
</form>

but this results in a javascript error: this object dont use that method (or
something, its in german).

With which user agent have you tested?
Where am i wrong here?

The code is error-prone and unreliable. Use something like

<form
name="bestellen"
method="post"
action="myPage.cfm?ID=4300&amp;do=action">
<input type="hidden" name="category" value="2">
<input type="hidden" name="Product" value="423">
<input type="hidden" name="Price" value="15">
<input type="hidden" name="action" value="basket">
<input type="hidden" name="Quantity" id="Quantity" value="1">
<input type="submit" value="Bestellen">
</form>

instead. (If you don't like the style of the "submit" button, you can
change that with CSS [e.g. you can make it look like a link if you like].
You can even use type="image" to use an image as submit button. In
contrast to your present code, a submit button will work everywhere
[although type="image" support is restricted to more recent browsers].)


HTH

PointedEars

P.S.: de.comp.lang.javascript exists :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top