JavaScript - How To Access An Object In Another Javascript File
Hi,
I'm very new to javascript and I need your help. What I'm trying to do is: I have a html file with javascipt embeded in, in this file I want to use a table object in another javascript file. How do I access this object? Your help is very much appreciated. Regards, lep2 Similar TutorialsHi all, Have problem from getting data of JavaScript Object ie. Associative Array. Code: var a, table1 a = new ActiveXObject("MyProgID"); a.GetDataFromExcel("C:\\Users\\myFolder\\Desktop\\test.xls","Sheet1") a.Generate() table1 = a.writeInTable(); Here writeInTable function returns a 2D Object array from DLL written in VB.Net. So I got the Object to table1. But from table1, I can't access the values but its there. table1 shows values as in this image(Image Attached.) Actually, I tried many ways like tab(0)(0) tab[0][0] tab["0"] tab.(0).(0) tab.[0].[0] Also with toArray(), (new VBArray(tab)).toArray().... I don't know what I am wrong..Can anyone help me on this? Thanks... Shanmugavel.C Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. I have a JS method register in a TD element as below: <td Id="MyTd" ondragenter="MyMethod('MyParam')" /> Below is the Js Method: function MyMethod(MyParam) { event.dataTransfer.dropEffect = 'move'; } The JS method works fine in IE but in mozilla throws an error that event is undefined. I cant pass the event object from HTML while registering the method as HTML is written by someone else and I cannot change that. All I can change is the JS method. How can i access the event object in JS method. Thanks. Hello Members. Firstly, I will explain why it is necessary. I am designing a site that will NOT be run from servers and will be accessed directly from a hard drive in a LAN environment only. Therefore no server side scripting is possible. Secondly, the data contained in the database is not important and only contains city names, business line names and team names (i.e. it is simply a way of managing changes to our organizational structure rather than editing 100's of <select> options whenever one of our business lines changes locations). So, my aim is for the JavaScript to grab data from an Access database and then populate a few <select> objects such as: Code: <select name="Site" id="site"> <option>....list of all Sites....</options> <select name="Business Line" id="lines> <option>....list of Business Lines in that Site....</options> <select name="Teams" id="teams> <option>....list of teams in that Business Line on that Site....</options> Here is the connection script that I have so far which is fairly basic: Code: function siteSelect(){ adOpenForwardOnly = 0; adLockReadOnly = 1; adCmdText = 1; var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "C:\AAA Backup\Forms.mbd";Persist Security Info=False"; var ConnectObj = new ActiveXObject("ADODB.Connection"); var adoRecordSet = new ActiveXObject("ADODB.Recordset"); var sql = "SELECT SiteName FROM tblSite;"; this.states = []; ConnectObj.Open(myConnect); adoRecordSet.Open(sql, ConnectObj, adOpenForwardOnly,adLockReadOnly,adCmdText); while (adoRecordSet.EOF != true) { this.states[this.states.length]= adoRecordSet("SiteName").value; adoRecordSet.MoveNext(); } adoRecordSet.Close(); } however, it currently only grabs the site list so I would need additional queries that use variables such as: (this is guaranteed to be completely wrong!) Code: "SELECT lineName FROM tblSite WHERE lineName="siteID.value";"; or is it: Code: "SELECT lineName FROM tblSite WHERE lineName=" + 'siteID.value' + ";"; Not sure. I also have no idea how to actually get the record sets into the visible select objects in the <body>. If any one could offer some suggestions, point me in the direction of some functions or explain a method of accomplishing this task that would be great! Peace. i noticed today that if i type in my js file name in the url i get a download box, i have an htaccess on my site so this should not be happening, thats another issue.. my question is, is there a trick to creating a js file that cant be accessed in this manner, i was thinking about adding a php define statement as it comes from one source only, but i wanted to ask first to see if there was something on the js side i could do or is that strictly a htaccess or server side issue.. Hi, I am trying to access an XML file from a server in my JavaScript code. I have an XML file like this: -<stream version="1.2"> -<room id="simulator" time="128168557915"> -<dimention id=0 x="1.25" y="2.00"> <m mcu="160" sid="75"> </dimention> </room> -<room id="simulator" time="128168557928"> -<dimention id=0 x="1.95" y="1.86"> <m mcu="160" sid="55"> </dimention> </room> </stream> this file is generated by an application and I can access it from a URL ( since I am using the simulator for this application the XML is accessible from http://localhost:8081/feed/demo) This xml file is updated every few seconds and constantly growing. I have a javascript code which I've added the following code to it in order to use the data from XML file: <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://localhost:8081/feed/demo",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("room"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x")); document.write("</td><td>"); } document.write("</table>"); </script> Now here comes my problem: if I have the XML file saved on same drive as html page and I address it like this: xmlhttp.open("GET","floor.xml",false); it works fine, but when I pass the URL it doesn't. is there anything else I should do in case of loading the xml from URL? my second question is that I want to use the text values returned by xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x") in an if statement like this : if (valuereturned = 2.00) { do sth } what is the best way to do that, since the returned value is a text. I need the answer ASAP and I really appreciate your help, thanx :-) Hello! How can you make a bookmarklet access an external file? (C:/testFile). The external file code is simply: Code: alert("hello"); I have tried the following code to call my external file: Code: javascript:(function(){document.body.appendChild(document.createElement('script')).src='file::/C:/testFile';})(); ...but it's not working. Please help. I am using Windows 7 and IE8. Any solutions appreciated. Thanks in advance. Jman Hi All, I have a javascript application i have built http://dtp3.demodesign.co.uk/uploader/ Now this working in everything excluding IE but i don't under stand why it dose not work in IE it is a JSON Class that loads appends the content. and has an Iframe System to provide a powerful solution to work with AJAX to show file lists Any way if you go to that site it errors in Ie but work in every thing else any one got any idear why that is I have HTML page which use js function and worked fine b4 I pull out the javascripts function from that page. Then later, I created .js file for the js functions and test again, the function doesn't work anymore. In .js file, <script type="text/javascript"> var upload_number = 2; function addFileInput() { var d = document.createElement("div"); var file = document.createElement("input"); file.setAttribute("type", "file"); //file.setAttribute("name", "attachment"+upload_number); file.setAttribute("name", "ufile[]"); file.setAttribute("size", "40"); d.appendChild(file); document.getElementById("moreUploads").appendChild(d); upload_number++; } </script> ************* Then in html page, I put <script language="javascript" src="jsfile/test.js"></script> in the <head> tag and call the function in <body> tag, <div id="moreUploads"></div> <div id="moreUploadsLink" style="display:none;"> <a href="javascript:addFileInput();">Upload another File</a> </div> ******************** When I click on the Upload another file link, nothing appear. It worked b4 I create separate js file. Pls help me solving this problem and gimme suggestions. Thanks in advance! PY All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero hi, i want to make an ftp access page using javascript i know it's possible using "ftp://" , but when i use this, the browser loads a window with the ftp folder i want a javascript to get ftp access and to give the commands itself any1 who knows how to get ftp access and ability to give file send/receive/... commands with javascript? Hi, I want to access SQL database using javascript. I am passing 1 value to the java script but I want to pass that value further to the SQL query as an where clause parameter to retrieve data. If the value retrieves multiple or single data then how do i handle it. Is it possible to use dataset in javascript? Regards, Anthony. Hi someone please let me know the way to access a smarty value with javascript? my smarty value is = {$value.url} i want to access it like Code: <script type="text/javascript"> function load() { document.location = '{$value.url}'; } </script> i tried with wrapping code with {literal} {/literal} but it isnt working. can some one correct this please sorry for bad english Thanks Hello everybody, I am new in this forum (and I'm also new in web coding, but not in programming)... This is the first problem I met: I can't understand how to acccess a property in this snippet: Code: function FGGE() { this.totalExternals = 0; this.loadedExternals = 0; this.loadImage = function(image) { image.onload = function() { alert("Loaded 1: "+this.loadedExternals+"/"+this.totalExternals); }; alert("Loaded 2: "+this.loadedExternals+"/"+this.totalExternals); }; } Output is this: Loaded 1: NaN/undefined Loaded 2: 0/0 Could someone help me fixing "Loaded 1"? Thanks a lot This is a question more about an ASP.NET web application, but javascript is involved, so I'm hoping some javascript gurus can assist me. I'm working with a web application that needs to get access to an ASP.NET web control (a button) in javascript. The problen is that since the control is run on the server, javascript can't access it in the standard way (i.e. document.getElementById(controlId); ). I've actually solved this problem before in a different application, but my solution there doesn't seem to work here for some reason. I have this in an aspx file: Code: <script...> ... function myfun() { var b = document.getElementById("<%=SaveButton.ClientID%>"); alert(b); } </script> ... <asp:Button ID="SaveButton" Text="save" OnClientClick="myfun()" ClientIDMode="Static" runat="server" UseSubmitBehavior="False" /> I have a designer class in which the button is declared (and therefore exists in the server-side codebehind): Code: protected global::System.Web.UI.WebControls.Button SaveButton; But when I click on my button, the alert box says "null". Why am I not able to get my button in the javascript function? Some things to note: *The button exists within a content tag: Code: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> *I'm working within Visual Studios 2008. I have two servers jboss and ejabbered and i have deployed two html files, one on each as follows: testdirver.html deployed on ejabbered <html><head> <script> function viewmembers() {var w=window.open("http://192.168.56.134:8080/nkms1/kms/test.html");} </script> </head> <body><form name="sub" > <input type="text" id="to" name="to"> <button onClick= "viewmembers();"> </form></body></html> test.html on jboss <html> <script> function abc() {alert(window.opener.document.forms[0].to);} </script> <body onload=abc();></body></html> Problem: window.opener.document gives the js error "Access is Denied" which i am not able to understand. Exchanging the two files on the servers(i.e. testdriver.html on jboss and test.html on ejabbered works fine and i get the output [object]). So i am guessing there is something that has to do with the ejabbered server I am a relative javascript newbie. I wish to detect when a user is leaving a page, and want to know what s/he is doing to leave that page (browser BACK vs. clicked URL), and would like to be able to get this information from the ... document? Where is it held? How can I know this from within my script? Thanks Eric Here is the scenario friends, I have an html page which I load it on a server. I give the URL of this page to my clients. My clients have their digital certificate in their web browsers. There is some data on the html page which is filled by the clients. When the client hits the submit button, a java script should run from behind which should be able to pick up the digital certificate of the client which is laoded on their web browser. This information must be sent along with the data to the server. Is it possible to do this using Java script? Can we access Certificates on a system via Java script? Are there any API calls which can be used in Java script for this purpose? Any help will be appreciated. Thank you for your time. Regards, Rocky Hi All, I have html pages with code like <div> <script type="text/javascript" src="http://myserver2/mysite/addhtm.js"></script> </div> the script adds some html code and random images selected from second server inside an iframe tag in the div tag. I need to examine this added html and image properties in my page using javascript. A search on internet did not help, it says elements inside iframe coming from different domain can not be accessed. Is there any workaround or hack available to access iframe contents from page javascript? Thanks I am starting a new project soon. Now, the project is still in the stage of planning. But I am quite confuse now which programming language to implement. I am going to design a system where the normal users will update the data with the system while the data required changes will need system administrator to apporve it. I will need a database to keep those records (the data required update) so that the system admin can refer to the database and make changes. Do I have another choice instead of using Microsoft Access 2007 macros or VBA ? I prefer a web-based programming. Any suggestion, please ? |