JavaScript - Attempting To Put Javascript Into External File...problems
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? Similar TutorialsFirst, 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();"> 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? 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? 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. 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 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. Hey all, I'm fairly new to JavaScript. I learned PHP and now I'm creating a user registration and login system for an application I'm making and I decided I wanted to give JS a try. I'm trying to make a form validation function that will be called when I press the submit button on the form but I want to use an external js file to store all my custom functions. I have the OnClick event in the button with the call to my function inside of that. But where and how on the page to I reference my external file so that the button can call the function? Thanks guys! 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. Code: <!-- Add-in device.js files are placed here --> <div id="deviceScript"></div> What I have been doing is clearing this out when I select a new (add-in) device and append a script tag with its .src file. I have some vague idea that unhooking an external js file might remove its code from memory. If not is there a way to do so? Functions in different script files have the same name - for example, I use start() to set up each device. It seems that the latest device start() overwrites the one in memory - but I am not sure if overwrite means delete last one or whether there is some horrendous build up of dross going on. Any clarification appreciated. I have this file: IPToned.js Code: // ==UserScript== // @name IPToned // @namespace http://users9.jabry.com/chatleague // @description IPTorrents Filter Enhancements // ==/UserScript== alert("hello world"); I drag and drop it into Firefox (Ubuntu) and it opens it as if it were a txt file. I want it to make the alert so I can get to coding. Any suggestions? I'm trying to execute an php file (which is present on an other host) by javascript. I've got three files for this: The javascript that calls the main program (launch.htm): Quote: <html> <script type="text/javascript"> document.write(unescape("%3Cscript src='http://www.mysite.com/reservetest.js' type='text/javascript'%3E%3C/script%3E")); </script> </html> The main program: (reservetest.js) Quote: function goer() { var url = 'test.php'; var pars="x=4&y=3"; makeHttpRequest(url+"?"+pars, thanks); } function thanks(text) { document.write(text); //$("divname").innerHTML=text; } function $() { if (arguments.length == 1) return get$(arguments[0]); var elements = []; $c(arguments).each(function(el){ elements.push(get$(el)); }); return elements; function get$(el){ if (typeof el == 'string') el = document.getElementById(el); return el; } }; function makeHttpRequest(url, callback_function, return_xml) { var http_request, response, i; var activex_ids = [ 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE6 and older for (i = 0; i < activex_ids.length; i++) { try { http_request = new ActiveXObject(activex_ids[i]); } catch (e) {} } } if (!http_request) { alert('Unfortunately your browser doesnt support this feature.'); return false; } http_request.onreadystatechange = function() { if (http_request.readyState !== 4) { // not ready yet return; } if (http_request.status !== 200) { // ready, but not OK alert('There was a problem with the request.(Code: ' + http_request.status + ')'); return; } if (return_xml) { response = http_request.responseXML; } else { response = http_request.responseText; } // invoke the callback callback_function(response); }; http_request.open('GET', url, true); http_request.send(null); } goer(); And finally the test file (test.php): Quote: <html><body>just a test</body></html> It works fine when I use all three files on the same host. However when I use launch.htm on an other host (which is the idea behind it) it gives me 'There was a problem with the request (code 0)'. When I change the url variable within reservetest.js to a relative/absolute path it gives me a 'access denied' on http_request.open line. Main idea is to show the user (who puts the code from launch.htm) on his/her website the contents of my test.php file (which retrieves mysql data). I think it's a security issue with the http_request.open line. Is there a way to work around this? Or am I missing something here? I don't want to use an iframe to retrieve information from my other host. Hi I'm trying to call a external .js file that contains a function from a webpage, but haven't been able to discover how to reference the function. First, the function: Code: function biggestOfTwo(valueOne, valueTwo) { var big; if(valueOne > valueTwo) { big = valueOne; } else { big = valueTwo; } return big; } ... and the xhtml calling it... Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>An XHTML 1.0 Strict standard template</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script src="compare.js" type="text/javascript" /> </head> <body> <script type = "text/javascript"> var dataInput1; var dataInput2; dataInput1 = prompt("Enter the first number to be compared"); dataInput2 = prompt("Enter the second number to be compared"); alert("The biggest value is " + biggestOfTwo(dataInput1, dataInput2)); </script> </body> </html> According to the book Beginning JavaScript 4th Edn, this should work - why isn't it? Jenny Hello everybody, I am currently working on displaying KML-values of ElementTags within my KML File. I already integrated the KML file as an overlay to my Google Map. But how am I able to parse the GGeoXml-object or how am I able to parse external ("http://www.myexample.org/polygons.kml" instead of just "polygons.kml") XML-files? At the moment my code for loading the geoxml file looks like this: Code: function initialize(kmlFile) { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setUIToDefault(); map.setCenter(new GLatLng(53.763325,-2.579041), 9); // ==== Create a KML Overlay ==== if(!(kmlFile==null)){ //check if it doesnt start with "http://" if(!(kmlFile.startsWith("http://"))){ kmlFile = "http://" + kmlFile; $('kmllink').value = kmlFile; } var kml = new GGeoXml(kmlFile); //add Overlay to the googlemaps window map.addOverlay(kml); //$('subject').value = "SUBJECT"; //$('content').value = "CONTENT"; kml.gotoDefaultViewport(map); // Store center and zoom as properties of the object kml var centerKML= kml.getDefaultCenter(); var zoomKML = map.getZoom(); map.panTo(centerKML); map.setZoom(zoomKML); } } } And for parsing local XML-files this code works already: Code: function loadXML() { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","test.kml",false); xhttp.send(""); //xmlDoc=xhttp.responseXML; xmlDoc = xhttp.responseXML; var placemark=xmlDoc.getElementsByTagName("Placemark"); alert(placemark[0].getElementsByTagName("name")[0].childNodes[0].nodeValue); ajaxLoader("http://www.zki.dlr.de/mod/ext/fireModis/yesterday_en.kml","Placemark"); } My question: Is there any way to integrate parsing external xml files in any of these two functions? Best regards, TsEMaNN I have an issue with my javascript files loading (i.e. checking the source code of the page after having loaded yields working links to my external files and the JQuery loading for sure after running some test), but calling a function from my javascript file works in no way shape or form. For example, one test I was running was: From my .js file Code: $("p").click( function() { $(this).hide(); } ) This will work on a standalone page when I test it (not loading from external .js file), but not in the page I need to get my scripts running on. Hi, I need some help with a bit of a challenge. I need to allow users to spesify a file stored on their hard drive, read the file and populate a table and eventually a database. I can probably upload the file using <input type='file'> but what then? How do I access the file after this, or is there a better way? Using XMLHTTP gives 'access denied.....' I can not use PHP as the site does not support PHP. For those who know the environment - it's a QuickBase application I need to upload to....... Thanks Nic Hi guys. I've made a html file with three lists to populate different pages of my site. Then i've called the html with SSI. let me show the code the HTML with the list's Code: <div id="list_box"> <ul class="list"> <li><a href="#">item01</a></li> <li><a href="#">item02</a></li> <li><a href="#">item03</a></li> <li><a href="#">item04</a></li> <li><a href="#">item05</a></li> </ul> </div> <div id="list_box"> <ul class="list"> <li><a href="#">item06</a></li> <li><a href="#">item07</a></li> <li><a href="#">item08</a></li> <li><a href="#">item09</a></li> <li><a href="#">item10</a></li> </ul> </div> <div id="list_box"> <ul class="list"> <li><a href="#">item11</a></li> <li><a href="#">item12</a></li> <li><a href="#">item13</a></li> <li><a href="#">item14</a></li> <li><a href="#">item15</a></li> </ul> </div> the HTML with the list loaded 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>Untitled Document</title> <style type="text/css"> <!-- #list_box { height:100%; width: 100%; padding-top: 15px; padding-left: 30px; padding-right: 30px; padding-bottom: 20px; background-color: #cccccc; overflow: hidden; } ul.list li { list-style-type: none; text-align: left; text-decoration: none; } .list a:link, .list a:visited { font-family: "Courier New", Courier, monospace; font-size: 12px; line-height: 15px; color: #036; text-decoration: none; text-align: left; font-weight: bold; font-style: normal; } .list a:hover{ font-family: "Courier New", Courier, monospace; font-size: 12px; line-height: 15px; color: #ffffff; text-decoration: none; text-align: left; font-weight: bold; font-style: normal; } --> </style> </head> <body> <div id="list_box"> <!--#include file="list.html" --> </div> </body> </html> the zip with the sample I've made load_external.zip I wanted to ask how can I make an item from the list's to have a different css in the html with the loaded list's. because in each page one of the items (that are all buttons) will be up or should I say active. can someone tell me how can I do this please. Maybe with javascript? thanks in advance relatively new coder here definitely new to js and I can't figure out how to get this script linked into an external file every time I try nothing shows up. Code: <html> <head> <script language="JavaScript1.1"> <!-- var slideimages=new Array() var slidelinks=new Array() function slideshowimages(){ for (i=0;i<slideshowimages.arguments.length;i++){ slideimages[i]=new Image() slideimages[i].src=slideshowimages.arguments[i] } } function slideshowlinks(){ for (i=0;i<slideshowlinks.arguments.length;i++) slidelinks[i]=slideshowlinks.arguments[i] } function gotoshow(){ if (!window.winslide||winslide.closed) winslide=window.open(slidelinks[whichlink]) else winslide.location=slidelinks[whichlink] winslide.focus() } //--> </script> <title></title> </head> <body> <a href="javascript:gotoshow()"><img src="img1.jpg" name="slide" border=0 width=250 height=250></a> <script> <!-- //configure the paths of the images, plus corresponding target links slideshowimages("img1.jpg","img2.jpg","img3.jpg","img4.jpg","img5.jpg") slideshowlinks("#","#","#","#","#") //configure the speed of the slideshow, in miliseconds var slideshowspeed=3000 var whichlink=0 var whichimage=0 function slideit(){ if (!document.images) return document.images.slide.src=slideimages[whichimage].src whichlink=whichimage if (whichimage<slideimages.length-1) whichimage++ else whichimage=0 setTimeout("slideit()",slideshowspeed) } slideit() //--> </script> </body> </html> obviously get rid of html tags and <script></script> tags save it as file.js and then <script type="text/javascript" src="file.js"> </script> do i need to break this up into 2 files or something I can't get it to work Hello Guys, I have a question here.. I have a scroller on my pages that basically reads a text file and displays.. The problem that I am having is it doesn't update until I reload the page(even though the .txt file updates about every 3 minutes).. I would like it to update when the file has been changed.. Here is my page. PHP Code: <link rel="stylesheet" href="../../css/li-scroller.css" type="text/css"> <script src="../../js/jquery.li-scroller.1.0.js" type="text/javascript"></script> <script type="text/javascript" src="../../jquery-1.6.1.min.js"></script> <script type="text/javascript"> $(function(){ $("ul#ticker01").liScroll(); }); </script> <?php $file = file_get_contents ('playingnow.txt'); ?> <div class="scrollpos"> <ul id="ticker01"> <li><a href="#"><?php Echo $file;?></a></li> <!-- eccetera --> </ul> </div> What can I add to make it go out and reload just the div not the entire page? Please advise.. |