Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts

    Javascript variable not working

    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.
    PHP Code:
    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
    PHP Code:
    <script language="javascript" type="text/javascript">
    var 
    wichproducttypecolourdepthstore;
    </script> 
    script.js
    PHP Code:
    // 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 TypeErrorCannot 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;
        }

    Last edited by barkermn01; 12-17-2008 at 10:20 AM.
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •