View Full Version : Dynamically retrieving data upon click
section508
02-09-2005, 07:52 AM
Attempting an inline page help system. I got a bunch of empty divs with unique IDs, I want to populate them with database data when each gets clicked. I am trying to avoid having to retreive ALL the data and load it into JS, that would be easy but would kill the page loading time since each page will have different help text.
I thought that I could just do a document.writeln("<script src="page.php?id=thisid"></script>") and have page.php output the JavaScript to write to "thisid" object, but it does not work. No matter where I place "return false" in the links or return function, the page always changes location- unless I comment out the above document.writeln line. Currently page.php?id=thisid only outputs:
document.getElementByID('myid').style.innerHTML='test';
Of course there is a <div id="myid"></div> on the page...
So I am not sure where I have gone wrong?! :confused:
If anyone can think of a better way to do this, I am all ears!
section508
02-09-2005, 07:54 AM
Typeo, actually, it is document.writeln("<scrip"+"t src=\"page.php?id=thisid\"></scrip"+"t>")
Otherwise it would end the JS block...
delinear
02-09-2005, 12:42 PM
Although it's not ideal, one way you could get around the problem is using an <IFRAME>, for instance...
<script type="text/javascript">
function changePage(newPage, myID){
var page;
page = '<iframe SRC="'+newPage+'" frameborder="0"></iframe>';
window.document.getElementById(myID).innerHTML = page;
}
</script>
<p onClick="changePage('page.php?id=thisid', 'myID');">Click here</p>
<div id="myID"></div>Hope this helps.
section508
02-09-2005, 05:58 PM
Thanks Del., how can I make that cross browser? My only thought would be annoying pop-behinds and that would not work if someone has a pop-up killer running... Ideas?!
Basscyst
02-09-2005, 06:39 PM
The script above doesn't pop anything up or behind. It just replaces the context of the innerHTML with an iframe.
Basscyst
Willy Duitt
02-09-2005, 07:05 PM
You do not indicate where the value of thisid is defined...
But, something like this should work but you will need to work on thisid since you did not indicate if it was a variable, object or what...
<script type="text/javascript">
onload = function(){
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'page.php?id=thisid';
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
.....Willy
section508
02-10-2005, 06:59 PM
Willy, you totally rock! Thanks, exactly what I was trying to do! :thumbsup:
Willy Duitt
02-10-2005, 07:16 PM
Willy, you totally rock! Thanks, exactly what I was trying to do! :thumbsup:
I get the solution correct every now and then... :D
Cheers;
.....Willy
section508
02-11-2005, 06:47 AM
:thumbsup:
section508
02-12-2005, 08:11 AM
Oh, one more question, I have wrapped it in
if(typeof document.getElementsByTagName!="undefined"&&typeof document.createElement!="undefined")
and added a contingency plan for the incapable browsers. Is this the best way to verify that the browser is capable of executing this script and what browsers are not capable? Firebird 0.7 circa. 2003 and IE 6 circa. 2001 can run it without a problem...
section508
02-15-2005, 03:59 PM
hello?
Firebird 0.7 circa. 2003 and IE 6 circa. 2001 can run it without a problem...
yes, your catch-all is fine.
btw: Firebird was only a beta version of Firefox, so it hardly matters, given that the full version has been out for over 3 months now. can't see why they wouldn't have upgraded by now. someone get them telt otherwise!
section508
02-16-2005, 02:10 AM
Firebird needs no installation, runs straight out of the unzip directory, so I have both Firebird 0.7 and the installed Firefox 1.0 running. Thing is, Firebird loads MUCH faster and crashes far less often. Aside from a few neat extensions not available for Firebird I see no reason to use Firefox...
Aside from a few neat extensions not available for Firebird I see no reason to use Firefox...
ehm ... security updates. there are holes in Firebird (aka Firefox 0.7). that's the most important reason to upgrade.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.