From: Neil on
I have a form that looks like this:

<form onsubmit="return false;" action="[action]" method="post">
<textarea name="myText" cols="30" rows="3"></textarea>
<input type="button" name="button" value="Value2"
onClick="this.form.submit();"/>
<input type="button" name="button" value="Value2"
onClick="this.form.submit();"/>
</form>

When I look at the posted values, I do not have a value for the
button.
How can I tell which of these buttons the user pressed?

Thanks,
Neil

--
Neil Aggarwal, (281)846-8957
FREE trial: cPanel VPS with unmetered bandwidth
http://UnmeteredVPS.net/cpanel
From: Thomas 'PointedEars' Lahn on
Neil wrote:

> <form onsubmit="return false;" action="[action]" method="post">
> <textarea name="myText" cols="30" rows="3"></textarea>
> <input type="button" name="button" value="Value2"
> onClick="this.form.submit();"/>
> <input type="button" name="button" value="Value2"
> onClick="this.form.submit();"/>
> </form>
>
> When I look at the posted values, I do not have a value for the
> button.
> How can I tell which of these buttons the user pressed?

By RTFM and not shooting yourself in the foot:

<form action="..." method="post">
<textarea name="myText" cols="30" rows="3"></textarea>
<input type="submit" name="button" value="Value1" />
<input type="submit" name="button" value="Value2" />
</form>

Are you sure you want to use XHTML?


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: Garrett Smith on
Thomas 'PointedEars' Lahn wrote:
> Neil wrote:
>
>> <form onsubmit="return false;" action="[action]" method="post">
>> <textarea name="myText" cols="30" rows="3"></textarea>
>> <input type="button" name="button" value="Value2"
>> onClick="this.form.submit();"/>
>> <input type="button" name="button" value="Value2"
>> onClick="this.form.submit();"/>
>> </form>
>>
Using javascript to submit the form creates an unnecessary a11y barrier.

If you stop doing that; you should get the button value included in the
submission.

The reason for this can be explained.

When a form is submitted, the browser must determine which button was
activated (clicked) for the request.

Your form prevents normal submission with :
| <form onsubmit="return false;"

..

The INPUT button being clicked is a separate event.

>> When I look at the posted values, I do not have a value for the
>> button.
>> How can I tell which of these buttons the user pressed?
>
> By RTFM and not shooting yourself in the foot:
>

Link?

> <form action="..." method="post">
> <textarea name="myText" cols="30" rows="3"></textarea>
> <input type="submit" name="button" value="Value1" />
> <input type="submit" name="button" value="Value2" />
> </form>
>
> Are you sure you want to use XHTML?
>

Probably not; that small sample contains XHTML errors.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Eric Bednarz on
Garrett Smith <dhtmlkitchen(a)gmail.com> writes:

> […] an unnecessary a11y barrier.

Words fail me.

>> <form action="..." method="post">
>> <textarea name="myText" cols="30" rows="3"></textarea>
>> <input type="submit" name="button" value="Value1" />
>> <input type="submit" name="button" value="Value2" />
>> </form>

I appreciate the absence of scripting to submit a form, but I think it
is still customary to use different names for multiple submit buttons if
you want to know which one was a successful control server-side.

>> Are you sure you want to use XHTML?
>
> Probably not; that small sample contains XHTML errors.

Please don't feel shy about being specific.
From: Garrett Smith on
Eric Bednarz wrote:
> Garrett Smith <dhtmlkitchen(a)gmail.com> writes:
>
>> […] an unnecessary a11y barrier.
>
> Words fail me.
>
>>> <form action="..." method="post">
>>> <textarea name="myText" cols="30" rows="3"></textarea>
>>> <input type="submit" name="button" value="Value1" />
>>> <input type="submit" name="button" value="Value2" />
>>> </form>
>

That is not the code the OP posted. Did you change it?

> I appreciate the absence of scripting to submit a form, but I think it
> is still customary to use different names for multiple submit buttons if
> you want to know which one was a successful control server-side.
>

Customary?

>>> Are you sure you want to use XHTML?
>> Probably not; that small sample contains XHTML errors.
>
> Please don't feel shy about being specific.

Don't be scared to run the code through the w3c html validator and find
them for yourself.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/