Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Fields not updating correctly.
Old 08-25-2008, 11:02 AM Fields not updating correctly.
Experienced Talker

Posts: 33
Name: Toby Osbourn
Trades: 0
Sorry my first post is a question, but I am in quite a pickle and could use a fast response, normally I like to help people out on a new forum before asking my own stuff!

I have been handed a project to work on that was only half completed by my predecessor - I say half completed because they only tested their solution in Safari. I am sure you can take a fairly good guess at what my problem relates to; the code works fine in Firefox, Safari and Opera, but does not work in Internet Explorer.

I haven't looked at JavaScript in years properly and have never attempted anything ajax like before, so this is pitched way above my head - hopefully with some guidance here I will be able to work through it!

My problem seems to be that once one form auto completes, the code doesn't want to let other forms do the same. Each form will separately work and do what it needs to do, but as soon as one field is filled in automatically, no others will work.

I downloaded Fiddler and used to to make sure the requests were getting through ok, and they are.

The information that gets sent, and that gets recieved the first time you do it compared to the time you do it after something has already been updated is the exact same. But the first time the new information will get displayed, and the second time it will not.

Because the problem is so wide spread and encompasses a lot of code, I thought it best to ask if there are any common problems I should be checking into as opposed to posting huge chunks of code for just one example.
tosbourn is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-26-2008, 06:45 AM Re: Fields not updating correctly.
Experienced Talker

Posts: 33
Name: Toby Osbourn
Trades: 0
Someone on another board asked for some bits of code, I thought I would post them here too! Sorry there is so much of it, but I don't want to guess at what is 100% working correctly and then miss something out.

Basically this code when initiated should open up a window containing users, once a user is clicked, their details should be automatically fed into the previous form.

The link that starts it all off..
Code:
<a href="javascript:newChangePerson(1)" id="findperson" >
The newChangePerson() function
Code:
function newChangePerson  (mode, witness){                   
            a = $("selectPID");

            b = $("myid");
            if (!a) a = {"value":""};
            if (!b) b = {"value":""};
            if (!witness) witness = "";
            TS.person(a.value, b.value, mode, witness);
TS.person (if (modals) is commented out because I wanted to see if I could get it working making it follow the wraptabs route.
Code:
TS.person      = function( ind, accid, mode, dstField ){
    if (accid!="") accid   = "&accident="+accid;
    if (ind  !="") ind     = "&current="+ind;
    if (mode ==1 ) mode    = "find"  ;
    if (mode ==2 ) mode    = "new"   ;
    if (mode ==0 ) mode    = "choose";
    if (dstField=="") dstField = "selectPID";
    jsdst = dstField;
    dstField = "&dest="+dstField;
    /*if (modals){
        var width  = window.innerWidth  || document.body.clientWidth;
        var height = window.innerHeight || document.body.clientHeight;
        $(jsdst).value = window.showModalDialog("person.php?"+mode+ind+accid+dstField, "", "dialogWidth: "+(width-80)+"px; dialogHeight: "+(height-80)+"px; center:1");
        goFindPerson(jsdst);
    } else */
    
    TS.wrapTabs("person.php?"+mode+ind+accid+dstField, "Person");
}
TS.wrapTabs then brings up the new window.

Once you select the user you want, these are the next two methods that get used.
Code:
function Person_callback  ( ){                                // [l] responder to above 
    if (req.readyState == 4) {          
        if (req.status == 200) {        
            eval(req.responseText);
            if (peopleChoice == null){
                alert("No one with that name was found in the database, \n\nCreate a new person by filling out the remainder of these fields");
            } else if (peopleChoice.length==1) {
                // $('fname'    ).value = peopleChoice[0].fname ; // Already populated so why?
                // $('sname'    ).value = peopleChoice[0].sname ;                        
                //$('selectPID').value = peopleChoice[0].dbid  ;   
                peopleChoice[0].add = unescape(peopleChoice[0].add);
                add = peopleChoice[0].add.split("\n");
                {
                    $(pLookDest+"hnum").value = unescape(add[0]);
                    $(pLookDest+"hpcd").value = unescape(add[4]);
                    $(pLookDest+"hstr").value = unescape(add[1]);
                    $(pLookDest+"hcou").value = unescape(add[2]);
                    $(pLookDest+"hcty").value = unescape(add[3]);
                }
                $(pLookDest+'fname'    ).value = unescape(peopleChoice[0].fname  );                           
                $(pLookDest+'sname'    ).value = unescape(peopleChoice[0].sname  );                           
                $(pLookDest+'phone'    ).value = unescape(peopleChoice[0].phone  );                           
                $(pLookDest+'age'      ).value = unescape(peopleChoice[0].age    );                            
                dd_select(pLookDest+"gender",    unescape(peopleChoice[0].gender));                          
                dd_select(pLookDest+"pcat",      unescape(peopleChoice[0].catid ));                          
            } 
        }// status 200
    } //readystate
}//person callback
function applyPerson      ( ){                                // [l] fill fields with result 
    num = $("personpicker").options[$("personpicker").selectedIndex].value;
    $('selectPID').value = peopleChoice[num].dbid  ;   
    peopleChoice[num].add = unescape(peopleChoice[num].add);
    add = peopleChoice[num].add.split("\n");
    {
        $("hnum").value = add[1];
        $("hpcd").value = add[5];
        $("hstr").value = add[2];
        $("hcou").value = add[3];
        $("hcty").value = add[4];
    }
    $('fname'    ).value =          peopleChoice[num].fname; 
    $('sname'    ).value =          peopleChoice[num].sname; 
    $('phone'    ).value =          peopleChoice[num].phone ; 
    $('age'      ).value = unescape(peopleChoice[num].age);   
    dd_select("gender",             peopleChoice[num].gender);
    dd_select("pcat",               peopleChoice[num].catid );
    $("attentionPhrase"  ).innerText = "";
    //innerHTML fix
    var newdiv = document.createElement("div");
    newdiv.innerHTML = "";
    $("attentionContents").appendChild(newdiv);
    $("attentionActions").appendChild(newdiv);

    //$("attentionContents").innerHTML = "";
    //$("attentionActions" ).innerHTML = "";
    $("attention").style.display="none";
}
I don't think I have missed anything out, and again, apologies for the incredibly long post!
tosbourn is offline
Reply With Quote
View Public Profile
 
Old 08-26-2008, 08:02 AM Re: Fields not updating correctly.
Experienced Talker

Posts: 33
Name: Toby Osbourn
Trades: 0
I think I can condense this some...

I have been firing in alerts by way of a test to see where IE is falling short, and it never actually gets into the method to update the fields.

The call to the function (Person_callback()) is made from the following bit of code.

Code:
function goFindPerson     (obj){                              // [l] AJAJ person lookup 
            if (typeof obj=="string") obj = $(obj);                   //

            if ((obj.id == "witness1id")){
                spid = ($("witness1id").value);
                pLookDest = "w_1_";
            } else if (obj.id == "witness2id"){
                spid = ($("witness2id").value);
                pLookDest = "w_2_";
            } else { 
                spid = ($("selectPID").value);
                pLookDest = "";
            }

            req.onreadystatechange = Person_callback;            // Set callback function
            alert("TEST"+req);
            req.open("GET", "personlookup.php?id="+spid, true);       // Do a tainted SQL call
            req.send("");                                             // Run the thread
        }
Now I have followed this code through, and IE is getting to the end of it, so I can only assume one of two things, the first is I am in totally the wrong place and need to retrace my steps, and the other is that for some reason req.onreadystatechange = Person_callback; isn't doing anything the second time around - is there anyway I can confirm this? or is there any work arounds?
tosbourn is offline
Reply With Quote
View Public Profile
 
Old 08-26-2008, 08:17 AM Re: Fields not updating correctly.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Do we get a test URL?

because it's fairly difficult debugging without the backend system as well.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-26-2008, 08:37 AM Re: Fields not updating correctly.
Experienced Talker

Posts: 33
Name: Toby Osbourn
Trades: 0
Unfortunately it is on a local test system, BUT the problem was resolved about 5 minutes ago, it was a caching issue, the workaround was to use..

Code:
req.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
This ensures IE won't try and use cached data, most probably a rookie mistake but I am totally new to this ajax game!

Cheers anyway!
tosbourn is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Fields not updating correctly.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42549 seconds with 12 queries