JavaScript - Javascript Read External File
Hi,
i have a question, is JavaScript can read an external file? i have an ear file, can it read external file without the external file compile together in the ear file? can we do so? Similar TutorialsOk, I am currently working on an announcements portlet for a dashboard that my team is creating. What is desired is to be able to have this portlet access a stored text file (file can be edited so content is subject to change) that will have all the information needed for these announcements. The JavaScript will then write it into a html file. I am a novice at html, and javascript; and i was hoping that if anyone had any advice, ideas, or a helpful link that could point me in the right direction I would much appreciate it. I am having trouble with JavaScript code and do not know why it is not working. I have the code I think is right but it is not showing up in my browser when run. Any ideas? Also are there any other ways to read in an xml file using javascript? please list if so. First, this is my first time coding anything seriously. I've only dabbled here and there, but no more. Any and all tips are appreciated. I have a program that's designed to calculate total enemy health. Its does this by taking user input on the level and enemy name. The enemy level input determines the base health stat. The enemy name determines the percent multiplier. This all runs on an onClick() event. I originally had this all in my <head> in my html code. It ended up being more code than I expected. So i made it an external javascript file. I did remove the <script></script> tags, I believe I have the file properly linked using the src attribute. I'm at my wits end. This is my second day of trying. So here is the javascript code. Code: // JavaScript Document var series; var index; var indexValue; var base; var distance; var sequence; var enemyLv; var enemyPct; var enemyHp; var vOneFive; var wrongAlert; var enemyList; var enemyName; var enemyInput; var enemyLevel; var a = enemyLEVEL(); var b = enemyPCT(); var totalHp = a * b; //calculates enemyHp and enemyPct function calc(enemyHp, enemyPct) { a = enemyLEVEL(); b = enemyPCT(); totalHp = a * b; if(a && b !== -1){ document.getElementById('enemyTotalHp').innerHTML = totalHp; } else{ alert(wrong); } } //determines base stat for enemyHp function enemyLEVEL(enemyHp){ enemyLv = document.getElementById('enemyLevel').value; var enemyLvValue = enemyLv * 1; wrongAlert = "BURGA!"; //determines which HP sequence to run if(enemyLvValue <= 5){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '12345'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 70; distance = 13; sequence = base + (indexValue * distance); enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 10){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '5678910'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 122; distance = 24.8; sequence = base + (indexValue) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 15){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '101112131415'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 246; distance = 50; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 20){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '151617181920'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 496; distance = 129.8; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 45){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '2021222324252627282930313233343536373839404142434445'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 1145; distance = 120; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 50){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '454647484950'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 4145; distance = 133; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if (enemyLvValue <= 75){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '5051525354555657585960616263646566676869707172737475'; index = series.lastIndexOf(enemyLvValue); indexValue = index * 1; base = 4810; distance = 75; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if (enemyLvValue <= 99){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series = '75767778798081828384858687888990919293949596979899'; index = series.lastIndexOf(enemyLvValue); indexValue = index * 1; base = 6685; distance = 70; sequence = base + ((indexValue)/2) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 110){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series ='100101102103104105106107108109110'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 8435; distance = 70; sequence = base + ((indexValue)/3) * distance; enemyHp = sequence; return enemyHp; } else if(enemyLvValue <= 170){ enemyLv = document.getElementById('enemyLevel').value; enemyLvValue = enemyLv * 1; series ='110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170'; index = series.indexOf(enemyLvValue); indexValue = index * 1; base = 9130; distance = 70; sequence = base + ((indexValue)/3) * distance; enemyHp = sequence; return enemyHp; } else{ alert(wrongAlert); } } //determines enemyPct variable function enemyPCT(enemyPct){ enemyInput = document.getElementById('enemyUser').value; enemyName = enemyInput; enemyList = new Array(); enemyList[1] = "Vahra Go Vahra Delsaban Golmoro Goshin Fulyen Curtz SEED-Guardian (Tw) Special Ops (Assault) Bysha type-Koh21 Bysha type-Otsu32 Gohma Dilla Gohma Methna GSM-05 Seeker GSM-05B Bomalta GSM-05M Tirentos YG-01K BUGGE YG01U BUGGES YG-01Z BUG Deljaban Orcdillan Sendillan";//100% hp // enemyList[2] = "Ageeta Sageeta Rogue Wikko Special Ops (Vobis)"; //60% hp // enemyList[3] = "Pannon Bel Pannon Galdeen Kudetob Nava Ludda Naval Zoona Shagreece Lapucha Polty Badia Go Bajilla"; //70% hp // enemyList[4] = "Armed Servant (Obme) Armed Servant (Ozuna) Distova Volfu Olgohmon Bul Buna";//90% hp // enemyList[5] = "Koltova Kakwane Ollaka Rappy Polec AMF Heavy Infantry Armed Servant (Basta) SEED-Guardian (Kn) Delp Slami";//130%hp // enemyList[6] = "Booma Go Booma Jigo Booma Jishagara Vanda Vanda Merha Vanda Orga Rogue (Ogg) SEED-Guardian (Sa)";//150%hp // enemyList[7] = "Rogue (Jasse) Rogue Mazz Special Ops (Kanohne) Special Ops (Solda)";//180%hp // enemyList[8] = "Komazli Bead Groode Dilla Griena Grinna Bete C";//200%hp // enemyList[9] = "Bal Soza Gaozoran";//230%hp; // enemyList[10] = "Shinowa Hidoki" ;//250% hp // enemyList[11] = "Jaggo Jaggo Acte Jaggo Amure Jaggo Sonichi Zamvapas Galvapas Do Vol No Vol";//260% hp // enemyList[12] = "Mizura Gainozeros Grass Assassin Ubakrada Rappy Rappy Amure Rappy Latan Rappy Noel Rappy Paska";//300% hp // enemyList[13] = "Kamatoze Bafal Bragga";//320% hp // enemyList[14] = "Jarba Polavohra Hiru Vol Delnadian SEED-Ardite Zasharogan Lutus Jigga Orgdus Svaltus";//350% hp // enemyList[15] = "Tengohg Bil De Melan Bil De Vear Drua Gohra Kog Nadd Dilnazen Jusnagun SEED-Argine SEED-Vance SEED-Vitace Ryugtass";//400% hp // enemyList[16] = "Carriguine SEED-Venas";//450% hp // enemyList[17] = "Rappy Gugg Renvolt Magashi Grinna Bete S";//500% hp // enemyList[18] = "Rappy Igg";//550% hp // enemyList[19] = "Darbelan Alfort Tylor";//600% hp // enemyList[20] = "Kagajibari";//630% hp // enemyList[21] = "Gol Dova";//650% hp // enemyList[22] = "Zoal Goug"; //700% hp // enemyList[23] = "De Rol Le";//1000% hp // enemyList[24] = "SEED-Magashi";//1100% hp // enemyList[25] = "Alterazgohg Onmagoug";//1350% hp // enemyList[26] = "Adahna Dimmagolus Dark Falz";//1450% hp // enemyList[27] = "De Ragan Magas Maggahna";//1500% hp // enemyList[28] = "Dulk Fakis Mother Brain";//1650% hp // enemyList[29] = "De Ragnus";//1720% hp var one = enemyList[1]; var two = enemyList[2]; var three = enemyList[3]; var four = enemyList[4]; var five = enemyList[5]; var six = enemyList[6]; var seven = enemyList[7]; var eight = enemyList[8]; var nine = enemyList[9]; var ten = enemyList[10]; var eleven = enemyList[11]; var twelve = enemyList[12]; var thirteen = enemyList[13]; var fourteen = enemyList[14]; var fifteen = enemyList[15]; var sixteen = enemyList[16]; var seventeen = enemyList[17]; var eighteen = enemyList[18]; var nineteen = enemyList[19]; var twenty = enemyList[20]; var twentyone = enemyList[21]; var twentytwo = enemyList[22]; var twentythree = enemyList[23]; var twentyfour = enemyList[24]; var twentyfive = enemyList[25]; var twentysix = enemyList[26]; var twentyseven = enemyList[27]; var twentyeight = enemyList[28]; var twentynine = enemyList[29]; // var indexOne = one.indexOf(enemyName); var indexTwo = two.indexOf(enemyName); var indexThree = three.indexOf(enemyName); var indexFour = four.indexOf(enemyName); var indexFive = five.indexOf(enemyName); var indexSix = six.indexOf(enemyName); var indexSeven = seven.indexOf(enemyName); var indexEight = eight.indexOf(enemyName); var indexNine = nine.indexOf(enemyName); var indexTen = ten.indexOf(enemyName); var indexEleven = eleven.indexOf(enemyName); var indexTwelve = twelve.indexOf(enemyName); var indexThirteen = thirteen.indexOf(enemyName); var indexFourteen = fourteen.indexOf(enemyName); var indexFifteen = fifteen.indexOf(enemyName); var indexSixteen = sixteen.indexOf(enemyName); var indexSeventeen = seventeen.indexOf(enemyName); var indexEighteen = eighteen.indexOf(enemyName); var indexNineteen = nineteen.indexOf(enemyName); var indexTwenty = twenty.indexOf(enemyName); var indexTwentyOne = twentyone.indexOf(enemyName); var indexTwentyTwo = twentytwo.indexOf(enemyName); var indexTwentyThree = twentythree.indexOf(enemyName); var indexTwentyFour = twentyfour.indexOf(enemyName); var indexTwentyFive = twentyfive.indexOf(enemyName); var indexTwentySix = twentysix.indexOf(enemyName); var indexTwentySeven = twentyseven.indexOf(enemyName); var indexTwentyEight = twentyeight.indexOf(enemyName); var indexTwentyNine = twentynine.indexOf(enemyName); // var test = "YOU CAN DO IT LITTLE NICKY! BITE HIS ****ING HEAD OFF!"; // if(indexOne != -1){ var enemyPctValue = 1; enemyPct = enemyPctValue; return enemyPct; } // else if(indexTwo != -1){ var enemyPctValue = 0.6; enemyPct = enemyPctValue; return enemyPct; } // else if(indexThree != -1){ var enemyPctValue = 0.7; enemyPct = enemyPctValue; return enemyPct; } // else if(indexFour != -1){ var enemyPctValue = 0.9; enemyPct = enemyPctValue; return enemyPct; } // else if(indexFive != -1){ var enemyPctValue = 1.3; enemyPct = enemyPctValue; return enemyPct; } // else if(indexSix != -1){ var enemyPctValue = 1.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexSeven != -1){ var enemyPctValue = 1.8; enemyPct = enemyPctValue; return enemyPct; } else if(indexEight != -1){ var enemyPctValue = 2; enemyPct = enemyPctValue; return enemyPct; } else if(indexNine != -1){ var enemyPctValue = 2.3; enemyPct = enemyPctValue; return enemyPct; } else if(indexTen != -1){ var enemyPctValue = 2.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexEleven != -1){ var enemyPctValue = 2.6; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwelve != -1){ var enemyPctValue = 3; enemyPct = enemyPctValue; return enemyPct; } else if(indexThirteen != -1){ var enemyPctValue = 3.2; enemyPct = enemyPctValue; return enemyPct; } else if(indexFourteen != -1){ var enemyPctValue = 3.5; enemyPct = enemyPctValue; return enemyPct; } else if (indexFifteen != -1){ var enemyPctValue = 4; enemyPct = enemyPctValue; return enemyPct; } else if(indexSixteen != -1){ var enemyPctValue = 4.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexSeventeen != -1){ var enemyPctValue = 5; enemyPct = enemyPctValue; return enemyPct; } else if(indexEighteen != -1){ var enemyPctValue = 5.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexNineteen != -1){ var enemyPctValue = 6; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwenty != -1){ var enemyPctValue = 6.3; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyOne != -1){ var enemyPctValue = 6.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyTwo != -1){ var enemyPctValue = 7; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyThree != -1){ var enemyPctValue = 10; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyFour != -1){ var enemyPctValue = 11; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyFive != -1){ var enemyPctValue = 13.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentySix != -1){ var enemyPctValue = 14.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentySeven != -1){ var enemyPctValue = 15; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyEight != -1){ var enemyPctValue = 16.5; enemyPct = enemyPctValue; return enemyPct; } else if(indexTwentyNine != -1){ var enemyPctValue = 17.2; enemyPct = enemyPctValue; return enemyPct; } else{ alert(enemyName); } } and this is the html code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PSUpedia Enemy HP Calculator</title> <script type="text/javascript" src="hp_calc.js"> </script> </head> <body> <form> Enemy Level: <input type="text" id="enemyLevel"></br> Enemy Name: <input type="text" id="enemyUser"></br> <p>EnemyHp: <b id="enemyTotalHp"> </b></p></br> <input type="button" value="CLICK!" onClick="calc();"> </form> </body> </html> Hi I have 2 external javascript files added in the head section of a html file but neither will work. However, if i place the javascript code in the html file it work. I'm lost and need help. Could it be the onload function
Code: <body onload="showCookies(); startBanner();"> Can you place java code in an external javascript file (.js). For example can I do the following in my xx.js file. $(document).ready(function(){ <% execute some java code here %> ...execute some javascript code here... }) Can I do the above? Another question ... I know <% %> is to execute java code inside html. But what does <%-- - -%> mean? Thanks for any help. I have some HTML that I want to put in a Javascript file and reference the HTML through external Javascript file. So I have my page, example.html Code: <html> <head></head> <body> <script type="text/javascript src="../js/external.js"> </script> </body> </html> external.js Code: document.write("<p class="txt_medium style4"> example.com<br />101 Street St.<br />City, ST, ZIP</p><p class="txt_medium style4">"The Best website." </p>"); The above code is all on one line, but is not displaying on the page. PHP is out of the question too (_._) Any thoughts? this is my first time attempting this operation. I want to take some javascript out of my html. here is the original: Code: <!--div#9begin--><div style="float: left; height: 166px; width: 1px;"> <img alt="" src="images/border_short_vert.png" height="169" width="1" /> </div><!--div#9end--> <!--div#10begin--><div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;"> <img alt="" src="images/news.png" height="16" width="222" /><!--div#11begin--><div style="width: 225px; height: 155px; float: left;"></div><!--div#11end--> <script type="text/javascript">// <![CDATA[if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')} if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} // ]]> </script> </div><!--div#10end--> and here's my attempt: Code: <div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;"> <img alt="" src="images/news.png" height="16" width="222" /><script type="text/javascript" src="docwrite.js"></script> <div style="width: 225px; height: 155px; float: left;"></div> </div> along with my js: Code: if(document.layers) {document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')} if(document.getElementById||document.all) {document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"> <div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} what is the problem? Have I not performed the extraction properly? OK, There's a script on my site that's included like <script src='somePHPfile.php?params... etc It generates an image with some text in it and a few links. When I click 'view source' it just comes up with the <script> tags and nothing else. In Firefox, if I right click on the actual image and go to this frame > view source, I can see everything it's doing. Is there some way I can access this code with Javascript/jquery? I've tried html/dom parsers, etc. with no luck. I have a Java Script that displays a Daily Affirmation on a webpage from an array of 365 Affirmations within the same html webpage file. This makes the html file size way too large. So I would like for the java script to read the array from an external text file on the same website server. Please provide me the Code to insert within my script which will read the array from an external text file - and also the format that the array of 365 lines must be typed into the external text file. I am not a Javascript Programmer - and know nothing about Javascript, so please write your reply at my (lack of) knowledge Level. Thank you in advance! Here is the code I am using. <script language=javascript> <!-- Date.prototype.getDOY = function() {var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((this - onejan) / 86400000);} var today = new Date(); var DOY = today.getDOY(); var HL=new Array() //Configure the following array to hold the 365 HLs for each day of the year HL[1]='HL 1 goes here' HL[2]='HL 2 goes here' HL[3]='HL 3 goes here' // Jump to Day 224 of the year for this example only HL[224]='I am surrounding myself with positive and supportive people. When I nurture relationships that give me energy and enjoyment, I mirror my beliefs that I deserve such gifts.' HL[225]='Today I affirm my own worth and value, and discover that the world agrees with me.' HL[226]='I am sowing seeds based on a healthy belief in my own self-worth. My life is flourishing with growing love, contentment, and exciting possibilities.' HL[227]='HL 227 goes here' HL[228]='HL 228 goes here' // Jump to last HL for Day 365 of year - for this example only HL[365]='HL 365 goes here' document.write(HL[DOY]) //--> </script> Hello, I don't know if this can be done in Javascript, or requires any other language but i was wondering if this would be possible. I would like to embed this Javascript code in to a PHP file and then for it to run automatically upon the PHP file loading: Code: <td class="smallDesc"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </td> The Javascirpt is the Facebook Share button that basically allows users that have Facebook to share the page there currently on in their Facebook status by pressing the button, but if there not logged in it shows the login page, not a problem just continue the script. The current button i which is what i want to load automatically in the PHP file is located here, to test the functionalilty just click "Share" button in blue.. http://watch-movies-online.anyfilman...-Movie-17.html To summarise, i would like the above Javascript code to execute automatically upon pageload of this PHP file.. http://www.watch-movies-online.anyfi...p://google.com. If that could be done, and if this also is possible.. i would like for the "Share" button on the external page that is loaded from the Javascript code above to be clicked automatically so in effect when ever someone visits the PHP page after clicking "Click Here to Watch/Stream 2012 Online For Free" on this page it will automatically load the Facebook Share box, and automatically click the "Share" Button and then close the page if possible, but not required. Please feel free to ask any questions, i'll be happy to answer. Thanks in advance. Best Regards, Jonathan. Function to Read-In External "XML" datafiles on For Loop Can anyone help ? see: http://www.jcsweb.biz/mef/AnimGIF/XMLtemp_04c.htm for required output Javascript Function required: To read in 7 successive "XML" files (not pure XML format & held in "Gallery/Data" external dir in a For Loop: (US_SUMlev_2008.xml,US_SUMlev_2009.xml.....to US_SUMlev_2014.xml) These XML then succesively update a string variable "strXML" which forms the "data" populating a time-series chart. "strXML" then acts as the input to "setDataXML" which is the Chart's data update method (?) The sequential updating of "strXML" in a For Loop should the create a psuedo-animation effect in the chart. My code (see below in edited format or view source at above URL) will achieve what I want but the "strXML" variable update is currently HARD-CODED (rather than read from the XML files held in external directory "Gallery/Data" ). The required function will also need to strip out all linbreaks ("\n") from the external XML files in order to produce a single line of stringtext: eg HTML Code: Code: <chart animation='0' caption= 'Chart1' yAxisName=' % change' ><categories> <category label='2008' /> <category label='2009' /> <category label='2010' /> <category label='2011' /> <category label='2012' /> <category label='2013' /> <category label='2014' /></categories><dataset seriesName='zGDP_u' color='6600CC' renderAs='Column' dashed='1'><set value='0.000000' /></dataset><dataset seriesName='zCPI_u' color='0000DC' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='ERIb_u' color='FFAA26' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='RSH_u' color='FF0066' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='zER_u' color='00FF00' renderAs='Line' ><set value='0.000000' /></dataset></chart> The sequential updating of "strXML" is also NOT yet done in a For Loop but a fixed timing Animate() function which successivley activates the generateXML_200?() on a timedelay. Summary: Required Runstream in Function For Loop: Loop1: Read-in "Gallery/Data/US_SUMlev_2008.xml", strip out "\n", update strXML (& thus setDataXML) & update chart1 Loop2: Read-in "Gallery/Data/US_SUMlev_2009.xml", strip out "\n", update strXML (& thus setDataXML) & update chart1 etc etc until Loop7: Read-in "Gallery/Data/US_SUMlev_2014.xml", strip out "\n", update strXML (& thus setDataXML) & update chart1 If there was a way to "Freeze" and "Restart" this above function (ie pause the read-in of the next XML) as in current code that would be mighty fine too. Any help much appreciated Code: Code: <HTML> <HEAD> <script language="Javascript" SRC="FC_v3_2.js"></script> <script language="JavaScript"> var strXML; function generateXML_2008(){ strXML = "<chart animation='0' caption= 'Chart1' yAxisName=' % change' ><categories> <category label='2008' /> <category label='2009' /> <category label='2010' /> <category label='2011' /> <category label='2012' /> <category label='2013' /> <category label='2014' /></categories><dataset seriesName='zGDP_u' color='6600CC' renderAs='Column' dashed='1'><set value='0.000000' /></dataset><dataset seriesName='zCPI_u' color='0000DC' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='ERIb_u' color='FFAA26' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='RSH_u' color='FF0066' renderAs='Line' ><set value='0.000000' /></dataset><dataset seriesName='zER_u' color='00FF00' renderAs='Line' ><set value='0.000000' /></dataset></chart>" ; return strXML; } function generateXML_2009(){ TRUNCATED - extends data by 1 year} function generateXML_2010(){ TRUNCATED - extends data by 1 year} function generateXML_2011(){ TRUNCATED - extends data by 1 year} function generateXML_2012(){ TRUNCATED - extends data by 1 year} function generateXML_2013(){ TRUNCATED - extends data by 1 year} function generateXML_2014(){ strXML = "<chart animation='0' showValues='0' caption= 'Chart1' yAxisName=' % change' ><categories> <category label='2008' /> <category label='2009' /> <category label='2010' /> <category label='2011' /> <category label='2012' /> <category label='2013' /> <category label='2014' /></categories><dataset seriesName='zGDP_u' color='6600CC' renderAs='Column'><set value='0.000000' /><set value='-0.055113' /><set value='-0.022272' /><set value='0.052834' /><set value='0.029910' /><set value='0.016847' /><set value='0.003139' /></dataset><dataset seriesName='zCPI_u' color='0000DC' renderAs='Line' ><set value='0.000000' /><set value='0.000470' /><set value='-0.009643' /><set value='0.004135' /><set value='0.000321' /><set value='0.000019' /><set value='-0.000719' /></dataset><dataset seriesName='ERIb_u' color='FFAA26' renderAs='Line' ><set value='0.000000' /><set value='0.142439' /><set value='0.130952' /><set value='0.102297' /><set value='0.083231' /><set value='0.062888' /><set value='0.043371' /></dataset><dataset seriesName='RSH_u' color='FF0066' renderAs='Line' ><set value='0.000000' /><set value='0.238348' /><set value='0.000000' /><set value='0.002127' /><set value='0.001261' /><set value='0.011962' /><set value='0.015624' /></dataset><dataset seriesName='zER_u' color='00FF00' renderAs='Line' ><set value='0.000000' /><set value='-0.000155' /><set value='-0.006479' /><set value='-0.007280' /><set value='-0.000895' /><set value='0.003701' /><set value='0.005333' /></dataset></chart>" ; return strXML; } </script> <script language="JavaScript"> function UpdatestrXML_2008(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2008()); } //Update XML going to Fusion charts function UpdatestrXML_2009(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2009()); } //Update XML going to Fusion charts function UpdatestrXML_2010(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2010()); } //Update XML going to Fusion charts function UpdatestrXML_2011(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2011()); } //Update XML going to Fusion charts function UpdatestrXML_2012(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2012()); } //Update XML going to Fusion charts function UpdatestrXML_2013(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2013()); } //Update XML going to Fusion charts function UpdatestrXML_2014(){ var chartObj = getChartFromId("chart1Id"); //Get reference to chart object using Dom ID chartObj.setDataXML(generateXML_2014()); } //Update XML going to Fusion charts </script> <script language="JavaScript"> var start = 250 ; var delay = 350 // var delay = 2000 function Animate() { t1_2008=setTimeout("javascript:UpdatestrXML_2008();", start+delay*1 ) ; t1_2009=setTimeout("javascript:UpdatestrXML_2009();", start+delay*2 ) ; t1_2010=setTimeout("javascript:UpdatestrXML_2010();", start+delay*3 ) ; t1_2011=setTimeout("javascript:UpdatestrXML_2011();", start+delay*4 ) ; t1_2012=setTimeout("javascript:UpdatestrXML_2012();", start+delay*5 ) ; t1_2013=setTimeout("javascript:UpdatestrXML_2013();", start+delay*6 ) ; t1_2014=setTimeout("javascript:UpdatestrXML_2014();", start+delay*7 ) ; LOOP =setTimeout("javascript:Animate();", start+delay*8) ; } </script> <script language="JavaScript"> function FreezeAll() { clearTimeout(t1_2008); clearTimeout(t1_2009); clearTimeout(t1_2010); clearTimeout(t1_2011); clearTimeout(t1_2012); clearTimeout(t1_2013); clearTimeout(t1_2014); clearTimeout(LOOP); } </script> </HEAD> <body onload="Animate();" > <FORM NAME='Form1' Id='Form1' action='' method=''> <INPUT TYPE="button" class="button" value="Animate" onClick="Animate(); "> <INPUT TYPE="button" class="button" value="Freeze" onClick="FreezeAll();"> </FORM> <div id="chart1div"> FusionCharts </div> <script language="JavaScript"> var chart1 = new FusionCharts("MSColumnLine3D.swf", "chart1Id", "600", "400", "0", "1"); chart1.setDataXML("<chart></chart>"); //Initialize chart with empty data. We'll feed it data on the chart's FC_Rendered event. chart1.render("chart1div"); </script> </body> </HTML> Had no replies to my previous post ! http://www.codingforums.com/search.php?searchid=6740324 I have tried to manipulate some (pretty complex) code for reading external code seen here on CF but there was nothing on doing this in a "For Loop" so had no real success Can anyone assist ? Most Kind I use a PHP page to set elements of a text file on our web server and I want to create a javascript function to intermitently check the contents of that file and if an element in that file matches a criteria I want to act on it... So, I do this <script type="text/javascript"> t = setInterval("CHECKFILE()",5000); </script> This calls the CHECKFILE function every 5000ms <script type="text/javascript"> function CHECKFILE(){ } </script> How, in the CHECKFILE function can I read from a file called FILE.txt for example?? In PHP I can use $myFile = "FILE.txt"; $theData = file($myFile); And this gives me an array, with each element containing one line from the file Can I do similar in Javascript? Or can I add PHP into the JS to do it for me? Thanks hi i m creating a webpage using javascript and php where i need to upload a doc file or zip and read all the words in doc file if it is zip i need to read all the words in all the doc files. i m trying to upload using file input but it does not show path of file only file name how i m suppose to upload and read it. hi, i have looked all over the internet but i can't find anything that works. All i want to do is simply read from a text file. Thanks for some reason I am unable to read the file contents, or it could be something else, I added in some extra code to see where the script got to and I only get to see '1' on the output. Is there something else I have missed ? I am wanting to ready each line one by one and replace a phrase with another, then output the new line. I visit the 1.txt file in my browser and the file shows fine. var txtFile = new XMLHttpRequest(); txtFile.open("GET", "http://mysite.com/convertJS/1.txt", true); txtFile.onreadystatechange = function() { document.write("1<br>"); if (txtFile.readyState === 4) { // document is ready to parse. document.write("2<br>"); if (txtFile.status === 200) { // file is found document.write("3<br>"); allText = txtFile.responseText; lines = txtFile.responseText.split("\n"); document.write(lines + "<br>"); // I shall be altering the text in each line, search and replace, so only need to be able to read one line at a time. } } } txtFile.send(null); // close file. sorry that i used the quote method to post, but when i used [ code ] it corupted the text as the document . write lines?! I am wanting to setup a dependant drop down where when a user clicks on the first drop down, it changes the contents of the second. The way I intend to do this is via a csv file. I have found several scripts but I have been unable to get them to work. Two of which a http://answers.yahoo.com/question/in...3114347AA7GYJ7 http://purbayubudi.wordpress.com/200...ng-javascript/ The first is the better option from what I can see. but the problem is readyState seems to be always 1. I am wondering if someone could perhaps give me a few moments to see if I can get this to work or suggest a better solution. I don't want to use a database approach, at least not yet. Hi guys, here again with another question. I would parse a file, my js read fine an html file, but this one is an export from msword. I don't know if this is the problem. I can't change the file. here is how my js read: Code: <body> <input type='button' value='Load' onclick="doLoad()" /> <script type='text/javascript'> /* THIS IS THE FILE TO READ */ var fileToRead="test.html"; /* THIS FUNCTION IS TO READ THE HTML FILE */ function IO(U) {//LA MOD String Version. A tiny ajax library. by, DanDavis var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(); X.open('GET', U, false ); X.setRequestHeader('Content-Type', 'text/html') X.send(''); return X.responseXML;} function doLoad(){ /* HERE IS THE CALL TO READ THE FILE */ var orari=(IO(fileToRead)); var arrTR=orari.getElementsByTagName('tr'); var arrTD_3nd_line=arrTR[1].getElementsByTagName('td'); var arr_p_1c_3l=arrTD_3nd_line[0].getElementsByTagName('p'); alert(arr_p_1c_3l[0].nodeValue); } </script> and here is a snip of the html i read: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 10"> <meta name="Originator" content="Microsoft Word 10"> <link rel="File-List" href="orarioinvernale_file/filelist.xml"> <title>ORARI </title> <!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>Ufficio Stampa</o:Author> <o:Template>Normal</o:Template> <o:LastAuthor>Ufficio Stampa</o:LastAuthor> <o:Revision>4</o:Revision> <o:TotalTime>1</o:TotalTime> <o:Created>2005-11-28T12:25:00Z</o:Created> <o:LastSaved>2006-01-13T10:24:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>762</o:Words> <o:Characters>4344</o:Characters> <o:Company>mycomp</o:Company> <o:Lines>36</o:Lines> <o:Paragraphs>10</o:Paragraphs> <o:CharactersWithSpaces>5096</o:CharactersWithSpaces> <o:Version>10.2625</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:SpellingState>Clean</w:SpellingState> <w:GrammarState>Clean</w:GrammarState> <w:HyphenationZone>14</w:HyphenationZone> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--> <style> <!-- /* Font Definitions */ @font-face {font-family:"Comic Sans MS"; panose-1:3 15 7 2 3 3 2 2 2 4; mso-font-charset:0; mso-generic-font-family:script; mso-font-pitch:variable; mso-font-signatu 647 0 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} span.SpellE {mso-style-name:""; mso-spl-e:yes;} span.GramE {mso-style-name:""; mso-gram-e:yes;} @page Section1 {size:595.3pt 841.9pt; margin:70.85pt 2.0cm 2.0cm 2.0cm; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabella normale"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> <meta http-equiv="Content-Language" content="it"> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="4098"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--> </head> <body style="" bgcolor="#ccffff" lang="IT"> <div class="Section1"> <div style="text-align: center;"> </div> <table class="MsoNormalTable" style="width: 100%;" border="1" cellpadding="0" height="1733" width="100%"> <tbody> <tr style="height: 75.75pt;"> .... and so on.... the problem is that my error console (from firefox) when i click my read button (not when i load the page) gives me errors: Code: sintax error: source: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> if i comment this it give me: Code: missing tag </meta> source: </head> and if i put Code: </meta> another meta is required and so on. But i can't modify the source i read, so is there a way to read this file? Many thanks Backit Hi, i need to read a files contents to an array so that i can check which lines of the file i need to write back. im not very good with arrays and haven't had any luck so far. thanks Hi, I'm new to JavaScript and I'm having a bit of trouble understanding something that seems relatively simple. When I make changes to CSS in JavaScript using '.style' I'm changing the attribute values of inline CSS. Can I use JavaScript to change the attribute values of rules in an external CSS file? I have no CSS in my html and would like to know if I can grab the values of attributes in an external CSS file using JavaScript. Thank you. |