<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IProgrammable &#187; JavaScript</title>
	<atom:link href="http://www.iprogrammable.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iprogrammable.com</link>
	<description>Kawalerowicz Consulting News</description>
	<lastBuildDate>Wed, 15 Feb 2012 13:21:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<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/</link>
		<comments>http://www.iprogrammable.com/2009/06/12/easiest-way-to-have-2-submit-button-in-one-html-form/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 14:41:05 +0000</pubDate>
		<dc:creator>marcin.kawalerowicz</dc:creator>
				<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></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>    <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%">&lt;%</span><span style="color: blue">= </span>Html.Encode(ViewData[<span style="color: #a31515">"Message"</span>]) <span style="background: #ffee62 none repeat scroll 0% 0%">%&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">="javascript" </span><span style="color: red">type</span><span style="color: blue">="text/javascript"&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">="post"&gt;
        &lt;</span><span style="color: #a31515">input </span><span style="color: red">id</span><span style="color: blue">="text" </span><span style="color: red">name</span><span style="color: blue">="text" </span><span style="color: red">type</span><span style="color: blue">="text" </span><span style="color: red">value</span><span style="color: blue">="Hello from Action" /&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">="submit" </span><span style="color: red">value</span><span style="color: blue">="Go to action 1"
            </span><span style="color: red">onclick</span><span style="color: blue">="ChangeFormAction(this, '/Home/Action1')" /&gt;
        &lt;</span><span style="color: #a31515">input </span><span style="color: red">type</span><span style="color: blue">="submit" </span><span style="color: red">value</span><span style="color: blue">="Go to action 2"
            </span><span style="color: red">onclick</span><span style="color: blue">="ChangeFormAction(this, '/Home/Action2')" /&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><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">"Message"</span>] = text + <span style="color: #a31515">"1"</span>;

        <span style="color: blue">return </span>View(<span style="color: #a31515">"Index"</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">"Message"</span>] = text + <span style="color: #a31515">"2"</span>;

        <span style="color: blue">return </span>View(<span style="color: #a31515">"Index"</span>);
    }
}</pre>
<pre><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/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

