<?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>Random Snippets &#187; simulate</title>
	<atom:link href="http://www.randomsnippets.com/tag/simulate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomsnippets.com</link>
	<description>Random Snippets of Code for Web Developers</description>
	<lastBuildDate>Fri, 25 Nov 2011 23:28:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Simulate a button click via JavaScript</title>
		<link>http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/</link>
		<comments>http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 07:09:21 +0000</pubDate>
		<dc:creator>Allen Liu</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[javascript alert]]></category>
		<category><![CDATA[javascript check]]></category>
		<category><![CDATA[simulate]]></category>

		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/</guid>
		<description><![CDATA[There is a rare need for this type of functionality but I have found myself in a couple of situations where I needed it. Here is a quick demo of a button click that is simulated from another event handler. &#8230; <a href="http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is a rare need for this type of functionality but I have found myself in a couple of situations where I needed it.  Here is a quick demo of a button click that is simulated from another event handler.  In this case, the button click is invoked by checking a checkbox.</p>
<fieldset>
<legend>Demo</legend>
<input type="checkbox" onClick="document.getElementById('theSubmitButton').click();">Check the box to simulate a button click<br />
</p>
<input type="button" name="theSubmitButton" id="theSubmitButton" value="Button" onClick="alert('The button was clicked.');">
</fieldset>
<p><span id="more-10"></span><br />
Here is the HTML code including the JavaScript:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;checkbox&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;document.getElementById('theSubmitButton').click();&quot;</span><span style="color: #339933;">&gt;</span>Check the box to simulate a button click
<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;theSubmitButton&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;theSubmitButton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Button&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;alert('The button was clicked.');&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>If the button is clicked directly, a JavaScript alert will pop up with the following message:</p>
<p><code>The button was clicked.</code></p>
<p>The <strong>onClick</strong> event handler for the checkbox will access the HTML DOM button object and invoke the <code>click()</code> method.  This simulates the button click and invokes the alert.</p>
<p>If you found that my code was helpful in any way, shape, or form and would like to buy me a <strong>beer</strong>, please use the <strong>Donate</strong> button below =)  Cheers!</p>
<p><center></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="WB5GF5WQ6YE5U">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
</form>
<p></center></p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

