...

View Full Version : create div and place php file content in there



gilgalbiblewhee
03-04-2009, 06:58 PM
I want to create a div tag and place the:
includefiles/highlight_getText_forum.php?"+getKeyURL's content in there.

So far there are no errors but it's not working:


function forForumUse(){
var my_div = null;
var newDiv = null;

var req = createRequest();
if(req){
req.onreadystatechange = function(){
// create a new div element
// and give it some content
newDiv = document.createElement("div");
newDiv.setAttribute("style", "float: left; z-index: 3;");
//newDiv.innerHTML = "<h1>Hi there and greetings!</h1>";
// add the newly created element and it's content into the DOM
my_div = document.getElementById("addtodb");
document.body.insertBefore(newDiv, my_div);
//var c = document.getElementById('addtodb');
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
newDiv.innerHTML = req.responseText;
}
}
}
}
var divIds = new Array();
divIds[0] = document.getElementById('showbookdiv1'); //not that it matters
divIds[1] = document.getElementById('showchapterdiv1');
divIds[2] = document.getElementById('showversediv1');
divIds[3] = document.getElementById('showbookdiv2');
divIds[4] = document.getElementById('showchapterdiv2');
divIds[5] = document.getElementById('showversediv2');
var getKeyURL = "";

var bcv = new Array();
var bcvQuotes = new Array();

if(divIds[0].innerHTML!= 0){
bcvQuotes[0] = "book1=";
var bobj1 = document.getElementById('selbook1');
bcv[0] = bobj1.value;
getKeyURL += bcvQuotes[0]+bcv[0];
}
if(divIds[1].innerHTML!= 0){
bcvQuotes[1] = "&chapter1=";
var cobj1 = document.getElementById('selchapter1');
bcv[1] = cobj1.value;
getKeyURL += bcvQuotes[1]+bcv[1];
}
if(divIds[2].innerHTML!= 0){
bcvQuotes[2] = "&verse1=";
var vobj1 = document.getElementById('selverse1');
bcv[2] = vobj1.value;
getKeyURL += bcvQuotes[2]+bcv[2];
}
if(divIds[3].innerHTML!= 0){
bcvQuotes[3] = "&book2=";
var bobj2 = document.getElementById('selbook2');
bcv[3] = bobj2.value;
getKeyURL += bcvQuotes[3]+bcv[3];
}
if(divIds[4].innerHTML!= 0){
bcvQuotes[4] = "&chapter2=";
var cobj2 = document.getElementById('selchapter2');
bcv[4] = cobj2.value;
getKeyURL += bcvQuotes[4]+bcv[4];
}
if(divIds[5].innerHTML!= 0){
bcvQuotes[5] = "&verse2=";
var vobj2 = document.getElementById('selverse2');
bcv[5] = vobj2.value;
getKeyURL += bcvQuotes[5]+bcv[5];
for(a=0; a<6; a++){
if(document.getElementById('txtarea_'+[a]).value!= ""){
getKeyURL += "&txtarea" + [a] + "=";
}
getKeyURL += document.getElementById('txtarea_'+[a]).value;
}
}
//var getKeyURL = document.getElementById('displayurl').innerHTML
//document.write(getKeyURL);
req.open("GET","includefiles/highlight_getText_forum.php?"+getKeyURL,true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}

gilgalbiblewhee
03-04-2009, 08:01 PM
Ok I simplified. I have a createtag_hi.php file that simply says hi


function createRequest(){
var req = false;
try {
req = new ActiveXObject('Msxml2.XMLHTTP');
}catch (e2){
try{
req = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e3){
try{
req = new XMLHttpRequest();
}catch(e1){
req = false;
}
}
}
return req;
}
function sayHi(){
var newDiv = document.createElement("div");
newDiv.setAttribute('style', 'float: left; z-index: 3; background-color: #999999;');
newDiv.setAttribute('id', 'hiid');
var req = createRequest();
if(req){
req.onreadystatechange = function(){
var c = document.getElementById('hiid');
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
c.innerHTML = req.responseText;
}
}
}
}

//var getKeyURL = document.getElementById('displayurl').innerHTML
//document.write(getKeyURL);
req.open("GET","createtag_hi.php",true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}

I'm getting this error:

Error: c is null
Source File: http://...new/twotexts/js/createtag_ajax.js
Line: 42

gilgalbiblewhee
03-04-2009, 10:06 PM
What's wrong that the php file isn't going in the created element?


function sayHi(){
var req = createRequest();
if(req){
req.onreadystatechange = function(){
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
var newDiv = document.createElement("div");
newDiv.setAttribute('style', 'float: left; z-index: 3; background-color: #999999;');
newDiv.setAttribute('id', 'hiid');
newDiv.innerHTML = req.responseText;
//document.write(newDiv.innerHTML);
}
}
}
}
//var getKeyURL = document.getElementById('displayurl').innerHTML
//document.write(getKeyURL);
req.open("GET","createtag_hi.php",true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}
function sayHi(){
var req = createRequest();
if(req){
req.onreadystatechange = function(){
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
var newDiv = document.createElement("div");
newDiv.setAttribute('style', 'float: left; z-index: 3; background-color: #999999;');
newDiv.setAttribute('id', 'hiid');
newDiv.innerHTML = req.responseText;
//document.write(newDiv.innerHTML);
}
}
}
}
//var getKeyURL = document.getElementById('displayurl').innerHTML
//document.write(getKeyURL);
req.open("GET","createtag_hi.php",true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}

When I unblock the document.write it works on the new page. But when I block it doesn't work on the main page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum