<?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: How to change a Javascript File (.js file) with external values?</title>
	<atom:link href="http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values/feed" rel="self" type="application/rss+xml" />
	<link>http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values</link>
	<description></description>
	<pubDate>Tue, 22 May 2012 08:51:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Einstein</title>
		<link>http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values/comment-page-1#comment-3446</link>
		<dc:creator>Einstein</dc:creator>
		<pubDate>Thu, 12 Nov 2009 10:55:59 +0000</pubDate>
		<guid isPermaLink="false">http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values#comment-3446</guid>
		<description>&#60;!-- Paste this code into an external JavaScript file named: colorChange.js  --&#62;

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com

var sixteen;
var one;
var red;
var green;
var blue;
var colorCode;
var inputType = &#34;dec&#34;;

var ralpha = &#34;0123456789ABCDEF&#34;;
var temppos;
var rnumber;
hexArray = new Array();
  hexArray[0] = &#34;0&#34;;
  hexArray[1] = &#34;1&#34;;
  hexArray[2] = &#34;2&#34;;
  hexArray[3] = &#34;3&#34;;
  hexArray[4] = &#34;4&#34;;
  hexArray[5] = &#34;5&#34;;
  hexArray[6] = &#34;6&#34;;
  hexArray[7] = &#34;7&#34;;
  hexArray[8] = &#34;8&#34;;
  hexArray[9] = &#34;9&#34;;
  hexArray[10] = &#34;A&#34;;
  hexArray[11] = &#34;B&#34;;
  hexArray[12] = &#34;C&#34;;
  hexArray[13] = &#34;D&#34;;
  hexArray[14] = &#34;E&#34;;
  hexArray[15] = &#34;F&#34;;

rhexArray = new Array();
  rhexArray[0] = &#34;F&#34;;
  rhexArray[1] = &#34;E&#34;;
  rhexArray[2] = &#34;D&#34;;
  rhexArray[3] = &#34;C&#34;;
  rhexArray[4] = &#34;B&#34;;
  rhexArray[5] = &#34;A&#34;;
  rhexArray[6] = &#34;9&#34;;
  rhexArray[7] = &#34;8&#34;;
  rhexArray[8] = &#34;7&#34;;
  rhexArray[9] = &#34;6&#34;;
  rhexArray[10] = &#34;5&#34;;
  rhexArray[11] = &#34;4&#34;;
  rhexArray[12] = &#34;3&#34;;
  rhexArray[13] = &#34;2&#34;;
  rhexArray[14] = &#34;1&#34;;
  rhexArray[15] = &#34;0&#34;;


function d2h(number) { //converts a decimal number to hexadecimal
 sixteen = Math.floor(number/16); //value in the 16s position
 one = Math.floor(number-(sixteen*16)); //value in the 1s position
 sixteen = hexArray[sixteen]; //hex representation of the value in the 16s position
 one = hexArray[one]; //hex respresentation of the value in the 1s position
 number = sixteen + one; //concatenate string values of hex digits
 return number;
}

function h2d(number) { //converts hexadecimal numbers to decimal equivalents
 if(number.substring(0,1) == &#34;F&#34;) {
 sixteen = 15;
 } else if(number.substring(0,1) == &#34;E&#34;) {
 sixteen = 14;
 } else if(number.substring(0,1) == &#34;D&#34;) {
 sixteen = 13;
 } else if(number.substring(0,1) == &#34;C&#34;) {
 sixteen = 12;
 } else if(number.substring(0,1) == &#34;B&#34;) {
 sixteen = 11;
 } else if(number.substring(0,1) == &#34;A&#34;) {
 sixteen = 10;
 } else {
 sixteen = eval(number.substring(0,1));
 }
 sixteen = sixteen * 16;
 if(number.substring(1,2) == &#34;F&#34;) {
 one = 15;
 } else if(number.substring(1,2) == &#34;E&#34;) {
 one = 14;
 } else if(number.substring(1,2) == &#34;D&#34;) {
 one = 13;
 } else if(number.substring(1,2) == &#34;C&#34;) {
 one = 12;
 } else if(number.substring(1,2) == &#34;B&#34;) {
 one = 11
 } else if(number.substring(1,2) == &#34;A&#34;) {
 one = 10;
 } else {
 one = eval(number.substring(1,2));
 }
 return sixteen + one; //return sum of these decimal numbers
}

function changeFgColor(number) { //this function receives the background's hexadecimal color code
//as a parameter, and then returns a suitable font color that would
//be visible on that background color
 rnumber = &#34;&#34;;
 for(i=0; i &#60;= number.length-1; i++) {
  temppos = ralpha.indexOf(number.charAt(i));
  rnumber = rnumber + rhexArray[temppos];
 }
 return rnumber;
}

function changeBgColor() { //this function reads in values from the text fields, parses the text
//as a color code, and then changes the background color
 if(inputType == &#34;hex&#34;) { //if user has changed the hexadecimal field
  document.colorform.hextext.value = document.colorform.hextext.value.toUpperCase();
  if(document.colorform.hextext.value.substring(0,1) == &#34;#&#34;) { //if user placed &#34;#&#34; in front of hex color code
   colorCode = document.colorform.hextext.value.substring(1,7);
  } else {
  colorCode = document.colorform.hextext.value.substring(0,6);
 }
document.colorform.redtext.value = h2d(colorCode.substring(0,2)); //converts to red's decimal value
document.colorform.greentext.value = h2d(colorCode.substring(2,4)); //converts to red's decimal value
document.colorform.bluetext.value = h2d(colorCode.substring(4,6)); //converts to red's decimal value
document.bgColor = colorCode; //change background color
document.fgColor = changeFgColor(colorCode); //change font color to something readable
return false; //exit function
}

//if program reaches this point, the color code is to be based on inputted decimal values,
//as opposed to hexadecimal values

//check red's value range
 if (eval(document.colorform.redtext.value) &#62; 255 &#124;&#124; eval(document.colorform.redtext.value) &#60; 0) {
 alert(&#34;All values must be and less than or equal to 255 and greater than or equal to 0.&#34;);
 return false;
 }
 //check green's value range
 if (eval(document.colorform.greentext.value) &#62; 255 &#124;&#124; eval(document.colorform.greentext.value) &#60; 0) {
 alert(&#34;All values must be and less than or equal to 255 and greater than or equal to 0.&#34;);
 return false;
 }
 //check blue's value range
 if (eval(document.colorform.bluetext.value) &#62; 255 &#124;&#124; eval(document.colorform.bluetext.value) &#60; 0) {
 alert(&#34;All values must be and less than or equal to 255 and greater than or equal to 0.&#34;);
 return false;
 }

 red = d2h(eval(document.colorform.redtext.value)); //convert red's decimal value to hex
 green = d2h(eval(document.colorform.greentext.value));//convert green's decimal value to hex
 blue = d2h(eval(document.colorform.bluetext.value)); //convert blue's decimal value to hex

 colorCode = red + green + blue; //create hexadecimal color code
 document.bgColor = colorCode; //set background color
 document.fgColor = changeFgColor(colorCode); //change font color to something readable
 document.colorform.hextext.value = &#34;#&#34; + colorCode; //rewrite hex's text field with new color code
}

function changeInput(type) {
 inputType = type; //inputType is to determine whether the user is changing the decimal text fields,
 //or the hexadecimal text fields
}

function instruct() { //alerts user with instructions
 alert(&#34;Enter a Red, Green, or Blue value of 0 to 255 \nor enter a 6 digit Hex Color Code using numbers 0-9\nand letters A-F then click Change Background.&#34;);
}

_________________________________________________________


&#60;!-- Paste this code into the HEAD section of your HTML document.
     You may need to change the path of the file.  --&#62;

&#60;script type=&#34;text/javascript&#34; src=&#34;colorChange.js&#34;&#62;&#60;/script&#62;
_________________________________________________________


&#60;!-- Paste this code into the BODY section of your HTML document  --&#62;

&#60;div style=&#34;width: 300px; margin-left: 30%; background-color: #fff; color: #00009C; text-align: center; line-height: 1.5em; &#34;&#62;
&#60;form name=&#34;colorform&#34; onSubmit=&#34;changeBgColor(); return false;&#34;&#62;
Red: &#60;input type=&#34;text&#34; name=&#34;redtext&#34; size=&#34;3&#34; value=&#34;255&#34; onfocus=&#34;changeInput('dec')&#34;&#62;
Green: &#60;input type=&#34;text&#34; name=&#34;greentext&#34; size=&#34;3&#34; value=&#34;255&#34; onfocus=&#34;changeInput('dec')&#34;&#62;
Blue: &#60;input type=&#34;text&#34; name=&#34;bluetext&#34; size=&#34;3&#34; value=&#34;255&#34; onfocus=&#34;changeInput('dec')&#34;&#62;
&#60;br&#62;
Hex Code: &#60;input type=&#34;text&#34; name=&#34;hextext&#34; size=&#34;7&#34; value=&#34;#FFFFFF&#34; onfocus=&#34;changeInput('hex')&#34;&#62;
&#60;br&#62;
&#60;input type=&#34;submit&#34; value=&#34;Change Background&#34; style=&#34;background-color: #00009C; color: #fff;&#34;&#62;
&#60;br&#62;
&#60;input type=&#34;button&#34; value=&#34;Instructions&#34; onclick=&#34;instruct()&#34; style=&#34;background-color: #00009C; color: #fff;&#34;&#62;
&#60;/form&#62;
&#60;/div&#62;&lt;br&gt;&lt;b&gt;References : &lt;/b&gt;&lt;br&gt;</description>
		<content:encoded><![CDATA[<p>&lt;!&#8211; Paste this code into an external JavaScript file named: colorChange.js  &#8211;&gt;</p>
<p>/* This script and many more are available free online at<br />
The JavaScript Source :: <a href="http://javascript.internet.com" rel="nofollow">http://javascript.internet.com</a></p>
<p>var sixteen;<br />
var one;<br />
var red;<br />
var green;<br />
var blue;<br />
var colorCode;<br />
var inputType = &quot;dec&quot;;</p>
<p>var ralpha = &quot;0123456789ABCDEF&quot;;<br />
var temppos;<br />
var rnumber;<br />
hexArray = new Array();<br />
  hexArray[0] = &quot;0&quot;;<br />
  hexArray[1] = &quot;1&quot;;<br />
  hexArray[2] = &quot;2&quot;;<br />
  hexArray[3] = &quot;3&quot;;<br />
  hexArray[4] = &quot;4&quot;;<br />
  hexArray[5] = &quot;5&quot;;<br />
  hexArray[6] = &quot;6&quot;;<br />
  hexArray[7] = &quot;7&quot;;<br />
  hexArray[8] = &quot;8&quot;;<br />
  hexArray[9] = &quot;9&quot;;<br />
  hexArray[10] = &quot;A&quot;;<br />
  hexArray[11] = &quot;B&quot;;<br />
  hexArray[12] = &quot;C&quot;;<br />
  hexArray[13] = &quot;D&quot;;<br />
  hexArray[14] = &quot;E&quot;;<br />
  hexArray[15] = &quot;F&quot;;</p>
<p>rhexArray = new Array();<br />
  rhexArray[0] = &quot;F&quot;;<br />
  rhexArray[1] = &quot;E&quot;;<br />
  rhexArray[2] = &quot;D&quot;;<br />
  rhexArray[3] = &quot;C&quot;;<br />
  rhexArray[4] = &quot;B&quot;;<br />
  rhexArray[5] = &quot;A&quot;;<br />
  rhexArray[6] = &quot;9&quot;;<br />
  rhexArray[7] = &quot;8&quot;;<br />
  rhexArray[8] = &quot;7&quot;;<br />
  rhexArray[9] = &quot;6&quot;;<br />
  rhexArray[10] = &quot;5&quot;;<br />
  rhexArray[11] = &quot;4&quot;;<br />
  rhexArray[12] = &quot;3&quot;;<br />
  rhexArray[13] = &quot;2&quot;;<br />
  rhexArray[14] = &quot;1&quot;;<br />
  rhexArray[15] = &quot;0&quot;;</p>
<p>function d2h(number) { //converts a decimal number to hexadecimal<br />
 sixteen = Math.floor(number/16); //value in the 16s position<br />
 one = Math.floor(number-(sixteen*16)); //value in the 1s position<br />
 sixteen = hexArray[sixteen]; //hex representation of the value in the 16s position<br />
 one = hexArray[one]; //hex respresentation of the value in the 1s position<br />
 number = sixteen + one; //concatenate string values of hex digits<br />
 return number;<br />
}</p>
<p>function h2d(number) { //converts hexadecimal numbers to decimal equivalents<br />
 if(number.substring(0,1) == &quot;F&quot;) {<br />
 sixteen = 15;<br />
 } else if(number.substring(0,1) == &quot;E&quot;) {<br />
 sixteen = 14;<br />
 } else if(number.substring(0,1) == &quot;D&quot;) {<br />
 sixteen = 13;<br />
 } else if(number.substring(0,1) == &quot;C&quot;) {<br />
 sixteen = 12;<br />
 } else if(number.substring(0,1) == &quot;B&quot;) {<br />
 sixteen = 11;<br />
 } else if(number.substring(0,1) == &quot;A&quot;) {<br />
 sixteen = 10;<br />
 } else {<br />
 sixteen = eval(number.substring(0,1));<br />
 }<br />
 sixteen = sixteen * 16;<br />
 if(number.substring(1,2) == &quot;F&quot;) {<br />
 one = 15;<br />
 } else if(number.substring(1,2) == &quot;E&quot;) {<br />
 one = 14;<br />
 } else if(number.substring(1,2) == &quot;D&quot;) {<br />
 one = 13;<br />
 } else if(number.substring(1,2) == &quot;C&quot;) {<br />
 one = 12;<br />
 } else if(number.substring(1,2) == &quot;B&quot;) {<br />
 one = 11<br />
 } else if(number.substring(1,2) == &quot;A&quot;) {<br />
 one = 10;<br />
 } else {<br />
 one = eval(number.substring(1,2));<br />
 }<br />
 return sixteen + one; //return sum of these decimal numbers<br />
}</p>
<p>function changeFgColor(number) { //this function receives the background&#8217;s hexadecimal color code<br />
//as a parameter, and then returns a suitable font color that would<br />
//be visible on that background color<br />
 rnumber = &quot;&quot;;<br />
 for(i=0; i &lt;= number.length-1; i++) {<br />
  temppos = ralpha.indexOf(number.charAt(i));<br />
  rnumber = rnumber + rhexArray[temppos];<br />
 }<br />
 return rnumber;<br />
}</p>
<p>function changeBgColor() { //this function reads in values from the text fields, parses the text<br />
//as a color code, and then changes the background color<br />
 if(inputType == &quot;hex&quot;) { //if user has changed the hexadecimal field<br />
  document.colorform.hextext.value = document.colorform.hextext.value.toUpperCase();<br />
  if(document.colorform.hextext.value.substring(0,1) == &quot;#&quot;) { //if user placed &quot;#&quot; in front of hex color code<br />
   colorCode = document.colorform.hextext.value.substring(1,7);<br />
  } else {<br />
  colorCode = document.colorform.hextext.value.substring(0,6);<br />
 }<br />
document.colorform.redtext.value = h2d(colorCode.substring(0,2)); //converts to red&#8217;s decimal value<br />
document.colorform.greentext.value = h2d(colorCode.substring(2,4)); //converts to red&#8217;s decimal value<br />
document.colorform.bluetext.value = h2d(colorCode.substring(4,6)); //converts to red&#8217;s decimal value<br />
document.bgColor = colorCode; //change background color<br />
document.fgColor = changeFgColor(colorCode); //change font color to something readable<br />
return false; //exit function<br />
}</p>
<p>//if program reaches this point, the color code is to be based on inputted decimal values,<br />
//as opposed to hexadecimal values</p>
<p>//check red&#8217;s value range<br />
 if (eval(document.colorform.redtext.value) &gt; 255 || eval(document.colorform.redtext.value) &lt; 0) {<br />
 alert(&quot;All values must be and less than or equal to 255 and greater than or equal to 0.&quot;);<br />
 return false;<br />
 }<br />
 //check green&#8217;s value range<br />
 if (eval(document.colorform.greentext.value) &gt; 255 || eval(document.colorform.greentext.value) &lt; 0) {<br />
 alert(&quot;All values must be and less than or equal to 255 and greater than or equal to 0.&quot;);<br />
 return false;<br />
 }<br />
 //check blue&#8217;s value range<br />
 if (eval(document.colorform.bluetext.value) &gt; 255 || eval(document.colorform.bluetext.value) &lt; 0) {<br />
 alert(&quot;All values must be and less than or equal to 255 and greater than or equal to 0.&quot;);<br />
 return false;<br />
 }</p>
<p> red = d2h(eval(document.colorform.redtext.value)); //convert red&#8217;s decimal value to hex<br />
 green = d2h(eval(document.colorform.greentext.value));//convert green&#8217;s decimal value to hex<br />
 blue = d2h(eval(document.colorform.bluetext.value)); //convert blue&#8217;s decimal value to hex</p>
<p> colorCode = red + green + blue; //create hexadecimal color code<br />
 document.bgColor = colorCode; //set background color<br />
 document.fgColor = changeFgColor(colorCode); //change font color to something readable<br />
 document.colorform.hextext.value = &quot;#&quot; + colorCode; //rewrite hex&#8217;s text field with new color code<br />
}</p>
<p>function changeInput(type) {<br />
 inputType = type; //inputType is to determine whether the user is changing the decimal text fields,<br />
 //or the hexadecimal text fields<br />
}</p>
<p>function instruct() { //alerts user with instructions<br />
 alert(&quot;Enter a Red, Green, or Blue value of 0 to 255 \nor enter a 6 digit Hex Color Code using numbers 0-9\nand letters A-F then click Change Background.&quot;);<br />
}</p>
<p>_________________________________________________________</p>
<p>&lt;!&#8211; Paste this code into the HEAD section of your HTML document.<br />
     You may need to change the path of the file.  &#8211;&gt;</p>
<p>&lt;script type=&quot;text/javascript&quot; src=&quot;colorChange.js&quot;&gt;&lt;/script&gt;<br />
_________________________________________________________</p>
<p>&lt;!&#8211; Paste this code into the BODY section of your HTML document  &#8211;&gt;</p>
<p>&lt;div style=&quot;width: 300px; margin-left: 30%; background-color: #fff; color: #00009C; text-align: center; line-height: 1.5em; &quot;&gt;<br />
&lt;form name=&quot;colorform&quot; onSubmit=&quot;changeBgColor(); return false;&quot;&gt;<br />
Red: &lt;input type=&quot;text&quot; name=&quot;redtext&quot; size=&quot;3&quot; value=&quot;255&quot; onfocus=&quot;changeInput(&#8217;dec&#8217;)&quot;&gt;<br />
Green: &lt;input type=&quot;text&quot; name=&quot;greentext&quot; size=&quot;3&quot; value=&quot;255&quot; onfocus=&quot;changeInput(&#8217;dec&#8217;)&quot;&gt;<br />
Blue: &lt;input type=&quot;text&quot; name=&quot;bluetext&quot; size=&quot;3&quot; value=&quot;255&quot; onfocus=&quot;changeInput(&#8217;dec&#8217;)&quot;&gt;<br />
&lt;br&gt;<br />
Hex Code: &lt;input type=&quot;text&quot; name=&quot;hextext&quot; size=&quot;7&quot; value=&quot;#FFFFFF&quot; onfocus=&quot;changeInput(&#8217;hex&#8217;)&quot;&gt;<br />
&lt;br&gt;<br />
&lt;input type=&quot;submit&quot; value=&quot;Change Background&quot; style=&quot;background-color: #00009C; color: #fff;&quot;&gt;<br />
&lt;br&gt;<br />
&lt;input type=&quot;button&quot; value=&quot;Instructions&quot; onclick=&quot;instruct()&quot; style=&quot;background-color: #00009C; color: #fff;&quot;&gt;<br />
&lt;/form&gt;<br />
&lt;/div&gt;<br /><b>References : </b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhvrm</title>
		<link>http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values/comment-page-1#comment-3445</link>
		<dc:creator>dhvrm</dc:creator>
		<pubDate>Thu, 12 Nov 2009 10:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://projects11.com/domainname/how-to-change-a-javascript-file-js-file-with-external-values#comment-3445</guid>
		<description>You need to know the variable in the external JS file that holds the background color. That variable needs to have global scope.

Assuming you properly identify the variable with global scope that holds the value, then you can simply reassign its value inb your JavaScript.

You then need to ensure no other functions or statements in the external JS file reassign the value to the background color variable.&lt;br&gt;&lt;b&gt;References : &lt;/b&gt;&lt;br&gt;</description>
		<content:encoded><![CDATA[<p>You need to know the variable in the external JS file that holds the background color. That variable needs to have global scope.</p>
<p>Assuming you properly identify the variable with global scope that holds the value, then you can simply reassign its value inb your JavaScript.</p>
<p>You then need to ensure no other functions or statements in the external JS file reassign the value to the background color variable.<br /><b>References : </b></p>
]]></content:encoded>
	</item>
</channel>
</rss>

