<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>IProgrammable &#187; JavaScript</title>
	<link>http://www.iprogrammable.com</link>
	<description>Kawalerowicz Consulting News</description>
	<pubDate>Thu, 21 Jan 2010 16:11:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Easiest way to have 2 submit button in one html form</title>
		<link>http://www.iprogrammable.com/2009_06_12/easiest-way-to-have-2-submit-button-in-one-html-form/en/</link>
		<comments>http://www.iprogrammable.com/2009_06_12/easiest-way-to-have-2-submit-button-in-one-html-form/en/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 14:41:05 +0000</pubDate>
		<dc:creator>Marcin Kawalerowicz</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[DHTML]]></category>

		<category><![CDATA[DotNet]]></category>

		<guid isPermaLink="false">http://www.iprogrammable.com/2009_06_12/easiest-way-to-have-2-submit-button-in-one-html-form/</guid>
		<description><![CDATA[Here is the easiest way to have two (or more) submit buttons in one html form and to make them “do” something else. It is very helpful if you are planning to implement a toolbar like behavior. Example is from ASP.NET MVC but it does not matter. Since it uses JavaScript to dynamically change the [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the easiest way to have two (or more) submit buttons in one html form and to make them “do” something else. It is very helpful if you are planning to implement a toolbar like behavior. Example is from ASP.NET MVC but it does not matter. Since it uses JavaScript to dynamically change the action attribute of a form tag, it can be used everywhere. Here it is:</p>
<pre class="code">    <span style="color: blue">&lt;</span><span style="color: #a31515">h2</span><span style="color: blue">&gt;</span><span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">&lt;%</span><span style="color: blue">= </span>Html.Encode(ViewData[<span style="color: #a31515">&#8220;Message&#8221;</span>]) <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">h2</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">script </span><span style="color: red">language</span><span style="color: blue">=&#8221;javascript&#8221; </span><span style="color: red">type</span><span style="color: blue">=&#8221;text/javascript&#8221;&gt;
        function </span>ChangeFormAction(sender, url) {
            sender.form.action = url;
        }
    <span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">form </span><span style="color: red">method</span><span style="color: blue">=&#8221;post&#8221;&gt;
        &lt;</span><span style="color: #a31515">input </span><span style="color: red">id</span><span style="color: blue">=&#8221;text&#8221; </span><span style="color: red">name</span><span style="color: blue">=&#8221;text&#8221; </span><span style="color: red">type</span><span style="color: blue">=&#8221;text&#8221; </span><span style="color: red">value</span><span style="color: blue">=&#8221;Hello from Action&#8221; /&gt;
        &lt;</span><span style="color: #a31515">br </span><span style="color: blue">/&gt;
        &lt;</span><span style="color: #a31515">input </span><span style="color: red">type</span><span style="color: blue">=&#8221;submit&#8221; </span><span style="color: red">value</span><span style="color: blue">=&#8221;Go to action 1&#8243;
            </span><span style="color: red">onclick</span><span style="color: blue">=&#8221;ChangeFormAction(this, &#8216;/Home/Action1&#8242;)&#8221; /&gt;
        &lt;</span><span style="color: #a31515">input </span><span style="color: red">type</span><span style="color: blue">=&#8221;submit&#8221; </span><span style="color: red">value</span><span style="color: blue">=&#8221;Go to action 2&#8243;
            </span><span style="color: red">onclick</span><span style="color: blue">=&#8221;ChangeFormAction(this, &#8216;/Home/Action2&#8242;)&#8221; /&gt;
    &lt;/</span><span style="color: #a31515">form</span><span style="color: blue">&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And the actions that responds to this form are here:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">HomeController </span>: <span style="color: #2b91af">Controller
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">ActionResult </span>Action1(<span style="color: blue">string </span>text)
    {
        ViewData[<span style="color: #a31515">&#8220;Message&#8221;</span>] = text + <span style="color: #a31515">&#8220;1&#8243;</span>;

        <span style="color: blue">return </span>View(<span style="color: #a31515">&#8220;Index&#8221;</span>);
    }

    <span style="color: blue">public </span><span style="color: #2b91af">ActionResult </span>Action2(<span style="color: blue">string </span>text)
    {
        ViewData[<span style="color: #a31515">&#8220;Message&#8221;</span>] = text + <span style="color: #a31515">&#8220;2&#8243;</span>;

        <span style="color: blue">return </span>View(<span style="color: #a31515">&#8220;Index&#8221;</span>);
    }
}</pre>
<pre class="code"><font face="Trebuchet MS">Nice!</font></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.iprogrammable.com/2009_06_12/easiest-way-to-have-2-submit-button-in-one-html-form/en/feed/en/</wfw:commentRss>
		</item>
	</channel>
</rss>
