[thelist] Another submit button for cancel

James Hardy evolt at weeb.biz
Wed Dec 15 09:48:39 CST 2004


And lo; it came to pass that the great prophet, Bird, Graham spake. And 
the huddled masses rejoiced to hear:
> Hi,
> 
> I have a form on which I want to provide a Cancel button.
> 
> My current idea is to have a second submit button (valid under W3C specs)...
> 
> <input type="submit" name="submit" value="Send" />
> <input type="submit" name="submit" value="Cancel" />
> 
> and send the user back to the page they came from if the submit value =
> "Cancel".
> 
> Is this a good idea, or am I stumbling blindly into a world of pain?
> 
> Cheers,
> 
> Graham
> 
> ...
Valid under the w3c spec, but try telling that to our good friends in 
Redmond. I have a number of pages that make use of this, however while 
firefox, opera and lynx will send submit=send or submit=cancel depending 
on which was clicked; Internet explorer will send both, making it 
impossible to work out which was clicked. Other than just reworking it 
to make the cancel button a link, there are two ways out.
1) have each button in it's own form. This is fairly easy, though adds a 
certain amount of code bloat.
2) use javascript, which is what I use on my site
<input type="submit" name="submit" value="Send" 
onclick="document.getElementById('ieHack').value='Send'"/>
<input type="submit" name="submit" value="Cancel" 
onclick="document.getElementById('ieHack').value='Cancel'"/>
<input type="hidden" name="ieHack" id="ieHack" value="none"/>

then on the receiving page (in ASP/VBScript, but simple to change to 
whatever)
<%
Select Case Request.Form("submit")
	case "Send"
	doSend()

	case "Cancel"
	doCancel()

	case "Else"
	'IE being crap
	Select Case Request.Form("submit")
		case "Send"
		doSend()

		case "Cancel"
		doCancel()

		case Else
		'JScript turned off
		doDisplayErrorMessage()
	End Select
End Select
%>

of course if the user is using IE, but has javascript turned off, this 
will not work. I usually display an error message in this case saying
"Sorry, due to browser deficiencies, users of Internet Explorer must 
have scripting enabled."




More information about the thelist mailing list