Prev: FAQ Topic - How do I check to see if a child window is open, before opening another? (2010-04-20)
Next: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2010-03-30)
From: Neil on 20 Apr 2010 15:43 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 20 Apr 2010 16:19 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 20 Apr 2010 16:52 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 20 Apr 2010 19:08 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 20 Apr 2010 20:43
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/ |