thecard Posted August 23, 2008 Share Posted August 23, 2008 I have 2 documents linked to a javascript. Document "B" is in a Frame on Document "A". Since both are linked to the javascript, how do I choose which document to output on? e.g. document.write("HELLO"); Can I choose to write that to either document? Quote Link to comment Share on other sites More sharing options...
s1yman Posted August 23, 2008 Share Posted August 23, 2008 I better first say that I'm not any good with JS. My understanding is that it works like document.object(); so I think that if you change "document" to whatever the document is called it should work. . . in theory. Hope that helps Quote Link to comment Share on other sites More sharing options...
thecard Posted August 23, 2008 Author Share Posted August 23, 2008 Thanks. Me being a noob at js I'm not sure either: It sounds like it shd work, but should it be the file name then .write? Quote Link to comment Share on other sites More sharing options...
s1yman Posted August 23, 2008 Share Posted August 23, 2008 oh, that's a good point, because if you put docB.html it will take the dot as another part, erm .. try to integrate this script to yours; http://forums.aspfree.com/html-javascript-and-css-help-7/calling-javascript-function-of-one-document-from-another-document-43150.html Quote Link to comment Share on other sites More sharing options...
thecard Posted August 23, 2008 Author Share Posted August 23, 2008 Well, my situation is rather complicated: Both documents share the same javascript page, but the framed document (B) has to pass variables to the js by query strings (in the url) there are 20 variables. I need to collect these variables in the js and output them onto document A. Thanks for your time. I really dunno how to do this. Quote Link to comment Share on other sites More sharing options...
s1yman Posted August 23, 2008 Share Posted August 23, 2008 so you got the <script language="javascript" src="charcount.js" /> then instead of outputting it from the script to docA, get docA to retrieve it from the script. . . will that work? Quote Link to comment Share on other sites More sharing options...
thecard Posted August 23, 2008 Author Share Posted August 23, 2008 How do you mean retrieve? Quote Link to comment Share on other sites More sharing options...
s1yman Posted August 23, 2008 Share Posted August 23, 2008 I might be completely off topic now because I'm attempting to apply php logic to javascript, probably prove fatal lol. As I said at the beginning I'm useless with JS, so sorry I can't help mate. Try something like this in your actual document where you want it to show; <script language="javascript" src="charcount.js">document.write("HELLO");</script> If not have a play around with it and wait for one of the gurus to get back to you. Quote Link to comment Share on other sites More sharing options...
thecard Posted August 23, 2008 Author Share Posted August 23, 2008 No, I need it to be in the main script. Sorry. Thanks for all the help. I hope some others try to help out! Quote Link to comment Share on other sites More sharing options...
thecard Posted August 25, 2008 Author Share Posted August 25, 2008 Please help. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 25, 2008 Share Posted August 25, 2008 Give the frame an ID like: <frame id='ken2k7'></frame> Then the JavaScript: document.getElementById("ken2k7").innerHTML = "YOUR_TEXT"; Quote Link to comment Share on other sites More sharing options...
thecard Posted August 25, 2008 Author Share Posted August 25, 2008 I know that, but the javascript is connected to 2 documents: The main page, and the Iframe. The Iframe calls the function in the javascript, and this function must write to a div tag in THE MAIN DOCUMENT. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 25, 2008 Share Posted August 25, 2008 I know that, but the javascript is connected to 2 documents: The main page, and the Iframe. The Iframe calls the function in the javascript, and this function must write to a div tag in THE MAIN DOCUMENT. So? I don't see a problem there? I think your JavaScript is probably not coded correctly. Do you mind providing the HTML and JavaScript you use? Quote Link to comment Share on other sites More sharing options...
thecard Posted August 26, 2008 Author Share Posted August 26, 2008 The HTML (MAIN DOCUMENT): <html> <head> <script type="text/javascript" src="js.js"> </script> </head> <body onLoad="doit();"> <a id="inner1"></a> <a id="inner2"></a> <a id="inner3"></a> <a id="inner4"></a> <a id="inner5"></a> <a id="inner6"></a> <a id="inner7"></a> <a id="inner8"></a> <a id="inner9"></a> <a id="inner10"></a> <a id="inner11"></a> <a id="inner12"></a> <a id="inner13"></a> <a id="inner14"></a> <a id="inner15"></a> <a id="inner16"></a> <a id="inner17"></a> <a id="inner18"></a> <a id="inner19"></a> <a id="inner20"></a> </body> </html> The PHP file (inside the iframe): I am not going to give you the exact code because it doesn't matter. The php does these actions mainly: Links to the javascript. Connects to a mysql database. GETS the $_GET['dom']; SELECTS 20 pieces of data from the database and passes them to the javascript in the dostuff function (which you can see in the javascript): The Javascript: function doit() { var mf = document.createElement("<iframe>"); mf.src = "http://mydomain.com/frame.php?dom=" + window.location; mf.width = "300px"; mf.height = "300px"; mf.frameborder="0"; mf.marginheight="0"; mf.marginwidth="0"; mf.id="mando"; document.body.appendChild(mf); } function dostuff(nav1,nav2,nav3,nav4,nav5,nav6,nav7,nav8,nav9,nav10,nav11,nav12,nav13,nav14,nav15,nav16,nav17,nav18,nav19,nav20) { var n1 = nav1; var n2 = nav2; var n3 = nav3; var n4 = nav4; var n5 = nav5; var n6 = nav6; var n7 = nav7; var n8 = nav8; var n9 = nav9; var n10 = nav10; var n11 = nav11; var n12 = nav12; var n13 = nav13; var n14 = nav14; var n15 = nav15; var n16 = nav16; var n17 = nav17; var n18 = nav18; var n19 = nav19; var n20 = nav20; document.getElementById("inner1").innerHTML = n1; } If you are correct the last line should put the variable n1 into the <a> tag with the id="inner1". This line does not write anything to the document. I know that vars n1 -> n20 do exist also because I have done lots of "alert tests" with them. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 26, 2008 Share Posted August 26, 2008 The function dostuff() is never called. Quote Link to comment Share on other sites More sharing options...
thecard Posted August 27, 2008 Author Share Posted August 27, 2008 Sorry -> it is called in the php file and the arguments are passed to it from the php. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 27, 2008 Share Posted August 27, 2008 Sorry -> it is called in the php file and the arguments are passed to it from the php. Is it called BEFORE the function is defined? Quote Link to comment Share on other sites More sharing options...
thecard Posted August 28, 2008 Author Share Posted August 28, 2008 There's nothing wrong with the actual function. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 28, 2008 Share Posted August 28, 2008 There's nothing wrong with the actual function. I didn't say anything was wrong with it. Could you show me the script that called the function? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.