...

View Full Version : Javascript variable not working



barkermn01
12-17-2008, 11:18 AM
hi all,

I'm using a loaded script file(check script.js code below) due to the lines of code i am using and i have a small amount on the page(again below)

now this is a script that will use AJAX unless it can't in that case it will use an iframe to load the data so allowing none AJAX browsers to use the script as well and im testing the iframe bit but for some reason the variable store is not saving data or it is being removed the page call the onload = getValues(); getList(product, type, colour, depth);
see below in script.js for what these do

This is the chuck of code that i bilive is not working and the page and javascript stop loading meaning it has completed it.


function iframeGet2($name){
while(store == undefined){
store = window.frames[$name].document.body.innerHTML;
if(store == undefined){
store = document.getElementById($name).contentDocument.body.innerHTML; //if frames dose not work IE 5.5+ Fix
}
}
document.getElementById('hold').innerHTML = '';//delete frame
}



script in page


<script language="javascript" type="text/javascript">
var wich, product, type, colour, depth, store;
</script>


script.js


// JavaScript Document
function GetXmlHttpObject(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Unsupported browser switching to compatibility mode!");
return false;
}
}
}
return ajaxRequest;
}

function generateAddress($product, $type, $colour, $depth){
if($product == '' || $product == undefined){
wich = 0;
return 'defines.php';
}
if(($type == '' || $type == undefined) && ($product != '' || $product != undefined)){
wich = 1;
return 'defines.php?PRODUCT='+$product;
}
if(($colour == "" || $colour == undefined) && ($type == '' || $type == undefined) && ($product != '' || $product != undefined)){
wich = 2;
return 'defines.php?PRODUCT='+$product+'&TYPE='+$type;
}
if(($depth == "" || $depth == undefined) && ($colour != "" || $colour != undefined) && ($type == '' || $type == undefined) && ($product != '' || $product != undefined)){
wich = 3;
return 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour;
}
if(($depth != "" || $depth != undefined) && ($colour != "" || $colour != undefined) && ($type == '' || $type == undefined) && ($product != '' || $product != undefined)){
wich = 4;
return 'defines.php?PRODUCT='+$product+'&TYPE='+$type+'&COLOUR='+$colour+'&depth='+$depth;
}
}

function count1($obj){
if($obj[0] != null){
return $obj.length;
}else{
return false;
}
}

function pause(millis)
{
var date = new Date();
var curDate = null;
do {
curDate = new Date();
}
while(curDate-date < millis);
}

function iframeGet($address, $name){
document.getElementById('hold').innerHTML = "<iframe onload=\"store = iframeGet2('" + $name + "');\" src=\"" + $address +"\" name=\""+ $name +"\" id=\"" + $name +"\"></iframe>";
}

function iframeGet2($name){
while(store == undefined){
store = window.frames[$name].document.body.innerHTML;
if(store == undefined){
store = document.getElementById($name).contentDocument.body.innerHTML; //if frames dose not work IE 5.5+ Fix
}
}
document.getElementById('hold').innerHTML = '';//delete frame
}

function ajaxGet($address, $handle){
$handle.open("GET",$address,true);
$handle.send(null);
$handle.onreadystatechange=function() {
if ($handle.readyState == 4){
$response = $handle.responseText;
print($response);
return $response;
}
if ($handle.readyState != 4){
pause(5000);
}
}
}

function fetchString($product, $type, $colour, $depth){
$address = generateAddress($product, $type, $colour, $depth);
$handle = GetXmlHttpObject();
if($handle == false){
//$text = iframeGet($address, document.getElementById("iframe"));
}else{
//$text = ajaxGet($address, $handle);
}
iframeGet($address, 'iframe')
}

function wichBox(){
if(wich == 0){
return document.getElementById("product");
}
if(wich == 1){
return document.getElementById("type");
}
if(wich == 2){
return document.getElementById("colour");
}
if(wich == 3){
return document.getElementById("depth");
}
if(wich == 4){
return false;
}
}

function getValues(){
product = document.getElementById("product").value;
type = document.getElementById("type").value;
colour = document.getElementById("colour").value;
depth = document.getElementById("depth").value;
}

function getList($product, $type, $colour, $depth){
$list = fetchString($product, $type, $colour, $depth);
$list = store;
$list = $list.split(/\s?\;\s{0,3}/g);
Uncaught TypeError: Cannot call method 'split' of undefined
$max = count1($list) - 1;
$i = 0;
$box = wichBox();
if($box != false){
while($i!= $max){
addOption($box,$list[$i],$list[$i],false);
$i++;
}
}else{
document.getElementById("cost").innerHTML = $list;
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum