<?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 and Ideas for any Web Developer</description>
	<lastBuildDate>Wed, 05 Aug 2009 14:32:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>Knix</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.  In this case, the button click is invoked by checking a checkbox.

Demo
Check the [...]]]></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 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>
]]></content:encoded>
			<wfw:commentRss>http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
