<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Convert a value to pixels with JavaScript</title>
	<atom:link href="http://www.chris-wallace.com/2008/11/12/convert-a-value-to-pixels-with-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chris-wallace.com/2008/11/12/convert-a-value-to-pixels-with-javascript/</link>
	<description>User experience designer and infamous WordPress developer.</description>
	<lastBuildDate>Thu, 08 Dec 2011 22:31:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://www.chris-wallace.com/2008/11/12/convert-a-value-to-pixels-with-javascript/comment-page-1/#comment-555</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 19 Jan 2009 15:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.chris-wallace.com/?p=173#comment-555</guid>
		<description>@Darren I agree with you, I don&#039;t think this function makes sense anymore. It originally was a larger function that checked to see if &#039;px&#039; was already a part of the string, and if yes, it should return the string untouched. The validation of the string is what I need. 

Here&#039;s the process I was looking for:
Check if passed variable is a number
  if yes return number+px
  if no strip alpha characters from beginning or end of number
    return number+px</description>
		<content:encoded><![CDATA[<p>@Darren I agree with you, I don&#8217;t think this function makes sense anymore. It originally was a larger function that checked to see if &#8216;px&#8217; was already a part of the string, and if yes, it should return the string untouched. The validation of the string is what I need. </p>
<p>Here&#8217;s the process I was looking for:<br />
Check if passed variable is a number<br />
  if yes return number+px<br />
  if no strip alpha characters from beginning or end of number<br />
    return number+px</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://www.chris-wallace.com/2008/11/12/convert-a-value-to-pixels-with-javascript/comment-page-1/#comment-553</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Mon, 19 Jan 2009 14:05:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.chris-wallace.com/?p=173#comment-553</guid>
		<description>Hi Chris,

I am just wondering why you need this function at all. As you can see by declaring &quot;var&quot; before a variable in javascript it does not really care if a string or integer is held in it unless you are doing validation or variable specific tasks. 

So .. First of all, you create your variable &quot;oldValue&quot; (which could be anything at all as input to your function) that should be an integer number to represent a pixel value in HTML - by adding &quot;px&quot;.

Why not simply state;

var oldvalue = &#039;65&#039;; (this has been created as a string - but javascript does not care)
var newValue = oldValue + &quot;px&quot;; (newValue is now equal to &quot;65px&quot;)

document.write(newValue);

Another thing is that by using the parseInt function (this function is used to parse an integer and return a string), in essence you are passing a string into a function that converts this to an integer, parses it and once again returns a string. This function is better suited to parsing strings that might contain both an integer and a string &quot;tail&quot; or in converting different numerical systems such as decimal to octal. You can see an example here : http://www.w3schools.com/jsref/jsref_parseInt.asp

The only purpose I could see in using this would be for validation but then there is nothing done inside the function px() to handle any errors. 

Its amazing how such a small piece of code can cause such a discussion, please let me know what it is that I may have missed.

Darren</description>
		<content:encoded><![CDATA[<p>Hi Chris,</p>
<p>I am just wondering why you need this function at all. As you can see by declaring &#8220;var&#8221; before a variable in javascript it does not really care if a string or integer is held in it unless you are doing validation or variable specific tasks. </p>
<p>So .. First of all, you create your variable &#8220;oldValue&#8221; (which could be anything at all as input to your function) that should be an integer number to represent a pixel value in HTML &#8211; by adding &#8220;px&#8221;.</p>
<p>Why not simply state;</p>
<p>var oldvalue = &#8217;65&#8242;; (this has been created as a string &#8211; but javascript does not care)<br />
var newValue = oldValue + &#8220;px&#8221;; (newValue is now equal to &#8220;65px&#8221;)</p>
<p>document.write(newValue);</p>
<p>Another thing is that by using the parseInt function (this function is used to parse an integer and return a string), in essence you are passing a string into a function that converts this to an integer, parses it and once again returns a string. This function is better suited to parsing strings that might contain both an integer and a string &#8220;tail&#8221; or in converting different numerical systems such as decimal to octal. You can see an example here : <a href="http://www.w3schools.com/jsref/jsref_parseInt.asp" rel="nofollow">http://www.w3schools.com/jsref/jsref_parseInt.asp</a></p>
<p>The only purpose I could see in using this would be for validation but then there is nothing done inside the function px() to handle any errors. </p>
<p>Its amazing how such a small piece of code can cause such a discussion, please let me know what it is that I may have missed.</p>
<p>Darren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/6 queries in 0.002 seconds using disk: basic
Object Caching 334/337 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: cdn.chris-wallace.com

Served from: www.chris-wallace.com @ 2012-02-09 13:38:42 -->
