<?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>Freelance PHP Web Developer London &#187; value</title>
	<atom:link href="http://rizfolio.com/blog/tag/value/feed/" rel="self" type="application/rss+xml" />
	<link>http://rizfolio.com/blog</link>
	<description>Freelance PHP/Web Developer walthamstow London. tutorials,scripts ecommerce solution guide and many more.</description>
	<lastBuildDate>Sun, 16 Aug 2009 16:29:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Radio button value with javascript</title>
		<link>http://rizfolio.com/blog/radio-button-javascript/</link>
		<comments>http://rizfolio.com/blog/radio-button-javascript/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 20:00:19 +0000</pubDate>
		<dc:creator>Rizwan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[checked]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[radio]]></category>
		<category><![CDATA[value]]></category>

		<guid isPermaLink="false">http://rizfolio.com/blog/?p=29</guid>
		<description><![CDATA[Tutorial to get / set value of a checkbox , radio button with javascript function. This funciton can be used to validate radio/checkbox.]]></description>
			<content:encoded><![CDATA[<p>This tiny little javascript function can really be helpfull during your webdevelopment work. I used them very often when it requires for  javascript validation or if there is need of AJAX work. I will try to explain in beginner mode so I can cover as many readers as I can, But I assume you must have some knowledge of  HTML/Javascript Syntax.</p>
<pre class="brush: jscript;">

function checkOptionValue(inputObj){
var objLength = inputObj.length;
if(objLength == undefined){
if(inputObj.checked)
return inputObj.value;
else
return &quot;&quot;;
}else{
for(var i = 0; i &lt; objLength; i++) {
if(inputObj[i].checked) {
return inputObj[i].value;
}
}
}
return &quot;&quot;;
}</pre>
<p>Another way to find out if object exists or not</p>
<pre class="brush: jscript;">
function objExists(objToTest) {
if (null == objToTest) {
return false;
}
if (&quot;undefined&quot; == typeof(objToTest) ) {
return false;
}
return true;
}
</pre>
<h3>function explained</h3>
<p>Pass the radio option as form object not the only the name  of the radio button.<br />
Example:  function  like checkOptionValue(document.form1.myoption);</p>
<p>var objLength = inputObj.length; &#8211; It gets the  length of the radio options.<br />
Example if there are 2 radio input like (male, female)  its length will be 2.</p>
<p>if(objLength == undefined){ &#8211; Check if there is only one  radio option, then length method will return undefined.</p>
<p>if(inputObj.checked) “checked” function returns true or  false, true  if option is checked/selected.</p>
<p>return inputObj.value; return the value of checked option.</p>
<p>Else return &#8220;&#8221;; if its not check return empty  string.</p>
<p>Else do a loop based on the length of the radio object</p>
<p>Keep checking if any option found checked return its value.</p>
<p><strong>Working Example</strong></p>
<p><script type="text/javascript"><!--
function checkOptionValue(inputObj){
	var objLength = inputObj.length;
	if(objLength == undefined){
		if(inputObj.checked)
			return inputObj.value;
		else
			return "";
	}else{
		for(var i = 0; i < objLength; i++) {
			if(inputObj[i].checked) {
				return inputObj[i].value;
			}
		}
	}
	return "";
}
// --></script></p>
<form method="post">Which language you like the most?</p>
<p><label></label></p>
<input id="RadioGroup1" name="RadioGroup1" type="radio" value="Javascript" /> Javascript</p>
<p><label></label></p>
<input id="RadioGroup1" name="RadioGroup1" type="radio" value="PHP" /> PHP</p>
<p><label></label></p>
<input id="RadioGroup1" name="RadioGroup1" type="radio" value="ASP .NET" /> ASP .NET</p>
<input id="button" onclick="javascript:alert('So you like '+checkOptionValue(document.form1.RadioGroup1)+'! ahaan..')" name="button" type="button" value="check" />
</form>
<p>NEXT: Setting the radio option value with javascript.<br />
<script src="http://rizfolio.com/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/shCore.js?ver=2.0.320" type="text/javascript"></script> <script src="http://rizfolio.com/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/shBrushPhp.js?ver=2.0.320" type="text/javascript"></script></p>
<p><script src="http://rizfolio.com/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/shBrushJScript.js?ver=2.0.320" type="text/javascript"></script> <script src="http://rizfolio.com/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/shBrushXml.js?ver=2.0.320" type="text/javascript"></script></p>
<p><script type="text/javascript"><!--
	SyntaxHighlighter.config.clipboardSwf = 'http://rizfolio.com/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/clipboard.swf';
	SyntaxHighlighter.config.strings.expandSource = 'expand source';
	SyntaxHighlighter.config.strings.viewSource = 'view source';
	SyntaxHighlighter.config.strings.copyToClipboard = 'copy to clipboard';
	SyntaxHighlighter.config.strings.copyToClipboardConfirmation = 'The code is in your clipboard now';
	SyntaxHighlighter.config.strings.print = 'print';
	SyntaxHighlighter.config.strings.help = '?';
	SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n';
	SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: ';
	SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: ';
	SyntaxHighlighter.all();
// --></script></p>
]]></content:encoded>
			<wfw:commentRss>http://rizfolio.com/blog/radio-button-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

