Quantcast
Channel: VBForums - jQuery
Viewing all articles
Browse latest Browse all 58

JSON Problem

$
0
0
Hi There

Im trying to create a little dialog where a net user can select a previous destination for a trip request.

Ive got a bit stuck working with the JSON
This is my entire class, I have used someone else's work to help me with get the visual box up.

The problem i think that i have is on the build_PastDestinations() function, Its doesn't seem to get past the starting $(function() and moves straight to the end of the function
it never seems get to here 'tablebody += "<tr><td>" + destination.Address + "</td></tr>";' before the the box appears.

The Json Looks like this [{"Address":"address1"},{"Address":"address2"}]



Code:

var winaddpick;
var AddPick;
var ExAddress;
var PickerSpanId = "PickerBoarder";
var apLeft = 0;
var apTop = 0;
var apWidth = 600;
var xpos = 0;
var ypos = 0;
var apHeight = 0;
var apPosOffsetX = -200; //X position offset relative to calendar icon, can be negative value
var apPosOffsetY = 0; //Y position offset relative to calendar icon, can be negative value

//Add Picker Prototype
function build_PastDestinations(){
        var tablebody = "<tbody>\n";
        $(function(){
                $.getJSON("phpscripts/getpastdestinations.php",function(data){
                        var destination="";
                        $.each(data,function(index,destination){
                                tablebody += "<tr><td>" + destination.Address + "</td></tr>\n";
                        });
                });
        });
        tablebody += "</tbody>\n"
        return tablebody;
}

function show_addpicker()
{
        var myaddresss = new Array();
        myaddresss[0] = "address 1";
        myaddresss[1] = "address 2";
        myaddresss[2] = "address 3";
        var PickerData = "<Span style='cursor:auto;'>";
        var vPickerHeader = "<Table Style='width:500px;padding:0;margin:5px auto 5px auto;text-align:center;'>/n<thead><tr><th>Previous Destinations</th></tr></thead>\n";
       
        var PickerBody = build_PastDestinations(); //"<tbody>\n";
        // var length = myaddresss.length;
        // for (var i = 0; i < length; i++)
        // {
                // PickerBody += "<tr><td>" + myaddresss[i] + "</td></tr>\n";
        // }
        var PickerCloser = "\n<tr>\n<td colspan='7' style=\"text-align:right;\">";
        PickerCloser += "<img onmousedown='javascript:close_win();' src='javascripts/dtp/images2/cal_close.gif'>";
        PickerCloser + "</td></tr>\n</tbody>\n</table>\n</span>";
        apHeight = 400;
        if (ypos > apHeight)
        {
                ypos = ypos - calHeight;
        }
        if (!winaddpick)
        {
                span = document.createElement("span");
                span.id = PickerSpanId;
                span.style.position = "absolute";
                span.style.left = (xpos + apPosOffsetX) + 'px';
                span.style.top = (ypos - apPosOffsetY) + 'px';
                span.style.width = apWidth + 'px';
                span.style.border = "solid 1pt #000000";
                span.style.padding = "0";
                span.style.backgroundColor = "#ffffff";
                span.style.zIndex = 100;
                document.body.appendChild(span);
                winaddpick = document.getElementById(PickerSpanId);
        }
        else
        {
                winaddpick.style.visibility = "visible";
                winaddpick.style.Height = apHeight;
               
        }
        winaddpick.innerHTML = PickerData + vPickerHeader + PickerBody + PickerCloser;
        return true;
}
function close_win()
{
        winaddpick.style.visibility = 'hidden';
}
function get_mPos(evt)
{
        var objectID,
        dom,
        de,
        b;
       
        if (document.addEventListener)
        { // w3c
                objectID = evt.target.id;
                if (objectID.indexOf(PickerSpanId) !== -1)
                {
                        dom = document.getElementById(objectID);
                        cnLeft = evt.pageX;
                        cnTop = evt.pageY;

                        if (dom.offsetLeft)
                        {
                                cnLeft = (cnLeft - dom.offsetLeft);
                                cnTop = (cnTop - dom.offsetTop);
                        }
                }
                xpos = (evt.pageX);
                ypos = (evt.pageY);
        }
        else
        {
                de = document.documentElement;
                b = document.body;
                xpos = event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
                ypos = event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
        }
}

document.onmousedown = get_mPos;

Id be quite happy to convert the JSON to an array first if that help. I can tell by using firebug that it is calling the PHP file and getting a response but nothing seems to happen with it

Hope some one can help

IAN

Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>