<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Brock Angelo &#187; Javascript</title>
	<atom:link href="http://brockangelo.com/category/code/javascript-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://brockangelo.com</link>
	<description>cool little projects</description>
	<lastBuildDate>Wed, 01 Sep 2010 17:07:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Replace Text on Click Using JavaScript</title>
		<link>http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/</link>
		<comments>http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 18:12:19 +0000</pubDate>
		<dc:creator>brockangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://brockangelo.com/?p=955</guid>
		<description><![CDATA[Did you know that you can replace text using Javascript? I wrote this script for our company intranet. In our staff phone directory I show the internal 5-digit phone number by default. Clicking the number reveals a 7-digit external phone number. Try the demo.


Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/' rel='bookmark' title='Permanent Link: Show Forms When Radio Button is Clicked'>Show Forms When Radio Button is Clicked</a></li><li><a href='http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/' rel='bookmark' title='Permanent Link: How to Reset a Form Using Javascript'>How to Reset a Form Using Javascript</a></li><li><a href='http://brockangelo.com/2009/03/18/search-and-replace-a-custom-field-in-wordpress-using-phpmyadmin/' rel='bookmark' title='Permanent Link: Search and Replace a Custom Field in WordPress using PHPMyAdmin'>Search and Replace a Custom Field in WordPress using PHPMyAdmin</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="/wp-content/themes/downtown-java-3column.js"></script><br />
<script type="text/javascript">
function toggle_text(shown, hidden) {
       var e = document.getElementById(shown);
       var f = document.getElementById(hidden);
    if(e.style.display == 'inline') {
			e.style.display = 'none';
			f.style.display = 'inline';
	}
	else {
			e.style.display = 'inline';
			f.style.display = 'none';
	}
}
</script><br />
This tutorial will show you how to replace text with text by using JavaScript. The text that you click will be replaced with new text. Specifically, we will use JavaScript to hide one div and show another in it&#8217;s place. Here is a demo:</p>
<blockquote><p><center><br />
<h2>
<div id="shown_first" style="display:inline"><a style="cursor:pointer" onclick="toggle_text('shown_first', 'hidden_first')">Click me	</a></div>
<div id="hidden_first" style="display:none"><a style="cursor:pointer" onclick="toggle_text('shown_first', 'hidden_first')">I used to be hidden!</a></div>
</h2>
<p></center></p></blockquote>
<p>JavaScript does the magic behind the scenes. The way you accomplish this is by putting your two text fields into divs. I&#8217;ll set the first one to be visible, then when you click on it, I will hide the first and show the second in its place. I use the <code>style.display</code> feature of JavaScript to change whether or not it is visible or shown. Let&#8217;s take a look at the JavaScript:</p>
<pre class="brush: javascript;">
&lt;script type=&quot;text/javascript&quot;&gt;

function toggle_text(shown, hidden) {
       var e = document.getElementById(shown);
       var f = document.getElementById(hidden);
    if(e.style.display == 'inline') {
			e.style.display = 'none';
			f.style.display = 'inline';
	}
	else {
			e.style.display = 'inline';
			f.style.display = 'none';
	}
}
&lt;/script&gt;
</pre>
<p>I&#8217;m simply passing in the two divs to the JavaScript function, then JavaScript checks whether or not the first div (the <code>shown</code> div) is visible or not. If it is visible, it hides it and shows the hidden one. The opposite happens if it isn&#8217;t visible. Note that using <code>inline</code> will display your text on the same line. If we wanted it to be on its own line, we could just use <code>block</code> instead.</p>
<p>Now you just need to insert the divs into the body of the page. Here is the code used from the sample above:</p>
<pre class="brush: html;">
&lt;div id=&quot;shown_first&quot; style=&quot;display:inline&quot;&gt;
	&lt;a style=&quot;cursor:pointer&quot; onclick=&quot;toggle_text('shown_first', 'hidden_first')&quot;&gt;
	Click me
	&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;hidden_first&quot; style=&quot;display:none&quot;&gt;
	&lt;a style=&quot;cursor:pointer&quot; onclick=&quot;toggle_text('shown_first', 'hidden_first')&quot;&gt;
	I used to be hidden!
	&lt;/a&gt;
&lt;/div&gt;
</pre>


<p>Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/' rel='bookmark' title='Permanent Link: Show Forms When Radio Button is Clicked'>Show Forms When Radio Button is Clicked</a></li><li><a href='http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/' rel='bookmark' title='Permanent Link: How to Reset a Form Using Javascript'>How to Reset a Form Using Javascript</a></li><li><a href='http://brockangelo.com/2009/03/18/search-and-replace-a-custom-field-in-wordpress-using-phpmyadmin/' rel='bookmark' title='Permanent Link: Search and Replace a Custom Field in WordPress using PHPMyAdmin'>Search and Replace a Custom Field in WordPress using PHPMyAdmin</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Show Forms When Radio Button is Clicked</title>
		<link>http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/</link>
		<comments>http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 16:18:51 +0000</pubDate>
		<dc:creator>brockangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[radio]]></category>
		<category><![CDATA[show]]></category>

		<guid isPermaLink="false">http://brockangelo.com/?p=862</guid>
		<description><![CDATA[Have you been on a website, clicked a radio button, and a form appears with text boxes that weren't there before? Here's free code to make that happen with Javascript.


Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/' rel='bookmark' title='Permanent Link: How to Reset a Form Using Javascript'>How to Reset a Form Using Javascript</a></li><li><a href='http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/' rel='bookmark' title='Permanent Link: Replace Text on Click Using JavaScript'>Replace Text on Click Using JavaScript</a></li><li><a href='http://brockangelo.com/2009/06/07/display-the-contents-of-a-file-using-php/' rel='bookmark' title='Permanent Link: Display the Contents of a File Using PHP'>Display the Contents of a File Using PHP</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using my Javascript a bit more than usual as I&#8217;ve been writing the <a href="http://brockangelo.com/wordpress/plugins/google-chart-generator/">Google Chart Generator</a> plugin for WordPress. Here is one that I think gives an awesome effect. You click a radio button or a checkbox and a form element shows up that wasn&#8217;t there before. This is helpful for Google Charts because datasets are only available for some types of charts. So it is easier for the user if they don&#8217;t show up unless they are needed. Here&#8217;s how it&#8217;s done:</p>
<p>Create a function inside your javascript tags in the head of your page. This checks to see which radio button was checked. If it is a pie chart, it shows the pie chart entry form and hides the line chart entry form. (and vice-versa) The &#8220;chart_type&#8221; gets passed in by the form (see below):</p>
<pre class="brush: javascript;">	function gcg_radio_check(chart_type) {

	if (chart_type == &quot;p3&quot;) {
	document.getElementById(&quot;pie_chart_data&quot;).style.display = &quot;block&quot;;
	document.getElementById(&quot;line_chart_data&quot;).style.display = &quot;none&quot;;
	}
	if (chart_type == &quot;lc&quot;) {
	document.getElementById(&quot;line_chart_data&quot;).style.display = &quot;block&quot;;
	document.getElementById(&quot;pie_chart_data&quot;).style.display = &quot;none&quot;;
	}
     }
</pre>
<p>Now we need to create our form element, and pass the chart_type value to javascript so it can decide what to do. We do this by passing &#8220;value&#8221; in the function parameter.</p>
<pre class="brush: html;">
&lt;form&gt;
&lt;input type=&quot;radio&quot; name=&quot;gcg_charttype&quot; onClick=&quot;gcg_radio_check(value);&quot; value=&quot;bhs&quot;&gt;Bar Chart&lt;br /&gt;
&lt;input type=&quot;radio&quot; name=&quot;gcg_charttype&quot; onClick=&quot;gcg_radio_check(value);&quot; value=&quot;lc&quot;&gt;Line Chart&lt;br /&gt;
&lt;/form&gt;
</pre>
<p>So if I clicked the radio button for &#8220;Bar Chart&#8221;, it passes this to javascript: <code>gcg_radio_check(bhs)</code></p>
<p>Lastly, we need to create the form that will be displayed once we click the radio box. I set it to <code>display:none</code> so that it is hidden by default:</p>
<pre class="brush: html;">
&lt;div id=&quot;pie_chart_data&quot; style=&quot;display:none&quot;&gt;
	&lt;h3&gt;Data Points&lt;/h3&gt;
	&lt;table&gt;
		&lt;tr&gt;
		&lt;input type=&quot;text&quot; size=&quot;4&quot; name=&quot;gcg_chartdata&quot; value=&quot;&quot;&gt; Data1
		&lt;input type=&quot;text&quot; size=&quot;6&quot; name=&quot;gcg_data_color&quot; value=&quot;&quot;&gt; Color
		&lt;input type=&quot;text&quot; size=&quot;10&quot; name=&quot;gcg_labels&quot; value=&quot;&quot;&gt; Label&lt;br /&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
&lt;/div&gt;
</pre>
<p>Then repeat this for the line chart and any other forms you want to hide or show.</p>


<p>Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/' rel='bookmark' title='Permanent Link: How to Reset a Form Using Javascript'>How to Reset a Form Using Javascript</a></li><li><a href='http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/' rel='bookmark' title='Permanent Link: Replace Text on Click Using JavaScript'>Replace Text on Click Using JavaScript</a></li><li><a href='http://brockangelo.com/2009/06/07/display-the-contents-of-a-file-using-php/' rel='bookmark' title='Permanent Link: Display the Contents of a File Using PHP'>Display the Contents of a File Using PHP</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Reset a Form Using Javascript</title>
		<link>http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/</link>
		<comments>http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 15:53:39 +0000</pubDate>
		<dc:creator>brockangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[reset]]></category>

		<guid isPermaLink="false">http://brockangelo.com/?p=854</guid>
		<description><![CDATA[How to Reset a Form Using Javascript

&#60;form&#62;
&#60;input type=&#34;button&#34; onclick=&#34;document.forms[0].reset()&#34; value=&#34;Reset This Form&#34;&#62;
&#60;/form&#62;

It doesn&#8217;t clear the data, it just resets all form values to their original value. Here&#8217;s a demo:







Related posts:Show Forms When Radio Button is ClickedReplace Text on Click Using JavaScriptHow to Add Uploaded Media to WP-DownloadManager


Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/' rel='bookmark' title='Permanent Link: Show Forms When Radio Button is Clicked'>Show Forms When Radio Button is Clicked</a></li><li><a href='http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/' rel='bookmark' title='Permanent Link: Replace Text on Click Using JavaScript'>Replace Text on Click Using JavaScript</a></li><li><a href='http://brockangelo.com/2009/05/12/how-to-add-uploaded-media-to-wp-downloadmanager/' rel='bookmark' title='Permanent Link: How to Add Uploaded Media to WP-DownloadManager'>How to Add Uploaded Media to WP-DownloadManager</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><strong>How to Reset a Form Using Javascript</strong></p>
<pre class="brush: javascript;">
&lt;form&gt;
&lt;input type=&quot;button&quot; onclick=&quot;document.forms[0].reset()&quot; value=&quot;Reset This Form&quot;&gt;
&lt;/form&gt;
</pre>
<p>It doesn&#8217;t clear the data, it just resets all form values to their original value. Here&#8217;s a demo:</p>
<form>
<input type="text" size="20" value="this comes back"></p>
<input type="text" size="20"></p>
<input type="button" class="button" onclick="document.forms[0].reset()" value="Reset This Form">
</form>


<p>Related posts:<ol><li><a href='http://brockangelo.com/2009/06/04/show-forms-when-radio-button-is-clicked/' rel='bookmark' title='Permanent Link: Show Forms When Radio Button is Clicked'>Show Forms When Radio Button is Clicked</a></li><li><a href='http://brockangelo.com/2009/06/19/replace-text-on-click-using-javascript/' rel='bookmark' title='Permanent Link: Replace Text on Click Using JavaScript'>Replace Text on Click Using JavaScript</a></li><li><a href='http://brockangelo.com/2009/05/12/how-to-add-uploaded-media-to-wp-downloadmanager/' rel='bookmark' title='Permanent Link: How to Add Uploaded Media to WP-DownloadManager'>How to Add Uploaded Media to WP-DownloadManager</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://brockangelo.com/2009/06/04/how-to-reset-a-form-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
