Dynamically Refreshing a DIV or other control from the Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philo Del Middleston

    Dynamically Refreshing a DIV or other control from the Server

    I've been searching, but apparently not phrasing my search right, so I'm
    going to float a question out here in the meantime...

    I'm wondering how to go about refreshing the content of a control (say, a
    selector) without refreshing the page. For example, if I have these selects:

    Company: <pick a company>
    Contact: <pick a contact>

    When they pick the company, I'd like to refill the contact selector based on
    who works for that company, but I don't want to refresh the form since the
    record hasn't been saved yet.

    I know I could use a hidden form or some embedded component to do an HTTP
    pull, but we have a live support app that we use and it seems like it might
    be keeping the connection to the server open until it's unloaded from the
    browser, so I was curious if that's doable, and how big a resource hog it
    is. We'll only have occasional instances where we'd need to do this sort of
    thing, but in those cases it would probably be worth it. I've been poking
    around in the live support code to find out how they do their refreshes, but
    I'm kind of new to PHP and I haven't spotted the answer yet.

    Thanks in advance...


  • Andy Hassall

    #2
    Re: Dynamically Refreshing a DIV or other control from the Server

    On Thu, 25 Sep 2003 15:18:28 -0400, "Philo Del Middleston"
    <bitbucket@sobr anisoft.com> wrote:
    [color=blue]
    >I've been searching, but apparently not phrasing my search right, so I'm
    >going to float a question out here in the meantime...
    >
    >I'm wondering how to go about refreshing the content of a control (say, a
    >selector) without refreshing the page.[/color]

    Javascript.

    --
    Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
    Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

    Comment

    • Philo Del Middleston

      #3
      Re: Dynamically Refreshing a DIV or other control from the Server

      Clearly I have to use Javascript for the client piece...

      The question is about how to do the server pull to get the fresh data. We
      have some clients with very large databases - I don't want to pull down the
      entire contacts table just so I can refresh the selector if the company
      changes.


      "Andy Hassall" <andy@andyh.co. uk> wrote in message
      news:h7g6nvk092 99osl8c3tgm668g ar1lke43c@4ax.c om...[color=blue]
      > On Thu, 25 Sep 2003 15:18:28 -0400, "Philo Del Middleston"
      > <bitbucket@sobr anisoft.com> wrote:
      >[color=green]
      > >I've been searching, but apparently not phrasing my search right, so I'm
      > >going to float a question out here in the meantime...
      > >
      > >I'm wondering how to go about refreshing the content of a control (say, a
      > >selector) without refreshing the page.[/color]
      >
      > Javascript.
      >
      > --
      > Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      > Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]


      Comment

      • Justin Koivisto

        #4
        Re: Dynamically Refreshing a DIV or other control from the Server

        Philo Del Middleston wrote:
        [color=blue]
        > I've been searching, but apparently not phrasing my search right, so I'm
        > going to float a question out here in the meantime...
        >
        > I'm wondering how to go about refreshing the content of a control (say, a
        > selector) without refreshing the page. For example, if I have these selects:
        >
        > Company: <pick a company>
        > Contact: <pick a contact>
        >
        > When they pick the company, I'd like to refill the contact selector based on
        > who works for that company, but I don't want to refresh the form since the
        > record hasn't been saved yet.
        >
        > I know I could use a hidden form or some embedded component to do an HTTP
        > pull, but we have a live support app that we use and it seems like it might
        > be keeping the connection to the server open until it's unloaded from the
        > browser, so I was curious if that's doable, and how big a resource hog it
        > is. We'll only have occasional instances where we'd need to do this sort of
        > thing, but in those cases it would probably be worth it. I've been poking
        > around in the live support code to find out how they do their refreshes, but
        > I'm kind of new to PHP and I haven't spotted the answer yet.
        >
        > Thanks in advance...
        >
        >[/color]

        Sounds a little confusing to me. What it sounds like you want is to make
        an onChange event for a SELECT element to display information based on
        that option's value. This sounds like you will need to make at least one
        HTTP/database request for each of the options - or for each time it's
        changed. I'd suggest an iframe element, then in the onChange javascript
        method, simply treat the IFRMAE as a named window (similar to in
        framesets), and reload its content that way.

        However, I think your comments about live support app and open server
        connections are confusing me. If you want to make no more subsequent
        requests until the data from the form is recorded, you'll have to find
        all the possible choices and save the content for those somewhere
        (likely with hidden elements) and make them visible when that option was
        chosen. However, it would seem to be much more efficient to request the
        data according to what the user chose since they aren't likely to go
        through every option (or are they?).

        --
        Justin Koivisto - spam@koivi.com
        PHP POSTERS: Please use comp.lang.php for PHP related questions,
        alt.php* groups are not recommended.

        Comment

        • Philo Del Middleston

          #5
          Re: Dynamically Refreshing a DIV or other control from the Server

          The other guy that responded with "Javascript ," while less than helpful, was
          actually correct. I haven't gotten to try it yet, but here's a page that
          appears to explain what I'm attempting to do:



          The whole application engine is XML based, and designed to run in a Windows
          client app or over the web. In the client app I can use window.external
          calls to pull whatever I need out of the database to rebuild an element, but
          I wasn't sure how I was going to translate that to the web version. I wanted
          to avoid using ActiveX controls or plugins since I don't want to be locked
          in to IE (although I will require a Javascript enabled browser).

          I would catch the onchange event for the first selector, make a quick fetch
          for the new set of contact names and id's for the new company selected, then
          rebuild the option list in the second selector.

          The live support app is doing image.src manipulation to do server pulls,
          although I never teased out exactly how they were getting the results. I'll
          have to go back now and see if they're doing DOM tricks like this article
          talks about.


          [color=blue]
          > Sounds a little confusing to me. What it sounds like you want is to make
          > an onChange event for a SELECT element to display information based on
          > that option's value. This sounds like you will need to make at least one
          > HTTP/database request for each of the options - or for each time it's
          > changed. I'd suggest an iframe element, then in the onChange javascript
          > method, simply treat the IFRMAE as a named window (similar to in
          > framesets), and reload its content that way.
          >
          > However, I think your comments about live support app and open server
          > connections are confusing me. If you want to make no more subsequent
          > requests until the data from the form is recorded, you'll have to find
          > all the possible choices and save the content for those somewhere
          > (likely with hidden elements) and make them visible when that option was
          > chosen. However, it would seem to be much more efficient to request the
          > data according to what the user chose since they aren't likely to go
          > through every option (or are they?).
          >
          > --
          > Justin Koivisto - spam@koivi.com
          > PHP POSTERS: Please use comp.lang.php for PHP related questions,
          > alt.php* groups are not recommended.
          >[/color]


          Comment

          • Andy Hassall

            #6
            Re: Dynamically Refreshing a DIV or other control from the Server

            On Thu, 25 Sep 2003 17:52:44 -0400, "Philo Del Middleston"
            <bitbucket@sobr anisoft.com> wrote:
            [color=blue]
            >The other guy that responded with "Javascript ," while less than helpful, was
            >actually correct. I haven't gotten to try it yet, but here's a page that
            >appears to explain what I'm attempting to do:
            >
            >http://www.webxpertz.net/faqs/jsfaq/jsserver.php
            >
            >The whole application engine is XML based, and designed to run in a Windows
            >client app or over the web. In the client app I can use window.external
            >calls to pull whatever I need out of the database to rebuild an element, but
            >I wasn't sure how I was going to translate that to the web version. I wanted
            >to avoid using ActiveX controls or plugins since I don't want to be locked
            >in to IE (although I will require a Javascript enabled browser).
            >
            >I would catch the onchange event for the first selector, make a quick fetch
            >for the new set of contact names and id's for the new company selected, then
            >rebuild the option list in the second selector.
            >
            >The live support app is doing image.src manipulation to do server pulls,
            >although I never teased out exactly how they were getting the results. I'll
            >have to go back now and see if they're doing DOM tricks like this article
            >talks about.[/color]

            Interesting stuff - hadn't occurred to me you could get the client to request
            and replace Javascript source using Javascript itself - I suppose it's part of
            the DOM after all so there's no reason why not.

            Provided you know your clients can handle this sort of fiddling it could be
            quite useful; this might actually end up applying to something on the intranet
            at work that's been bothering me... thanks!

            (My reply was overly brief as it looked like it was going offtopic)

            --
            Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
            Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

            Comment

            • Philo Del Middleston

              #7
              Re: Dynamically Refreshing a DIV or other control from the Server

              "Andy Hassall" <andy@andyh.co. uk> wrote in message
              news:08p6nv0fif bdpvn4hunktqof1 1ssvfn0p1@4ax.c om...[color=blue]
              > On Thu, 25 Sep 2003 17:52:44 -0400, "Philo Del Middleston"
              > <bitbucket@sobr anisoft.com> wrote:
              >[/color]
              [color=blue]
              > (My reply was overly brief as it looked like it was going offtopic)[/color]

              Well, I knew that this live support product was pulling the data out with
              PHP, so this seemed like the right place to go. I knew I could get the data
              into the document with Javascript, but getting the data looked like it was
              going to be a trick. Brief as your answer was, you got me headed in the
              right direction. I'll probably give this a shot tonight or tomorrow and I'll
              report back with my results.


              Comment

              • Jochen Daum

                #8
                Re: Dynamically Refreshing a DIV or other control from the Server

                Hi Philo!

                On Thu, 25 Sep 2003 15:43:14 -0400, "Philo Del Middleston"
                <bitbucket@sobr anisoft.com> wrote:
                [color=blue]
                >Clearly I have to use Javascript for the client piece...
                >
                >The question is about how to do the server pull to get the fresh data. We
                >have some clients with very large databases - I don't want to pull down the
                >entire contacts table just so I can refresh the selector if the company
                >changes.
                >[/color]

                Its really a question for comp.lang.javas cript and I actually asked it
                there 3 weeks ago. Short:

                - Use an iframe or different frame
                - Reload the frame with javascript and have a javascript array there.
                - copy it over into your select-box with javascript

                HTH, Jochen

                [color=blue]
                >
                >"Andy Hassall" <andy@andyh.co. uk> wrote in message
                >news:h7g6nvk09 299osl8c3tgm668 gar1lke43c@4ax. com...[color=green]
                >> On Thu, 25 Sep 2003 15:18:28 -0400, "Philo Del Middleston"
                >> <bitbucket@sobr anisoft.com> wrote:
                >>[color=darkred]
                >> >I've been searching, but apparently not phrasing my search right, so I'm
                >> >going to float a question out here in the meantime...
                >> >
                >> >I'm wondering how to go about refreshing the content of a control (say, a
                >> >selector) without refreshing the page.[/color]
                >>
                >> Javascript.
                >>
                >> --
                >> Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
                >> Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]
                >[/color]

                --
                Jochen Daum - CANS Ltd.
                PHP DB Edit Toolkit -- PHP scripts for building
                database editing interfaces.
                Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

                Comment

                • Philo Del Middleston

                  #9
                  Re: Dynamically Refreshing a DIV or other control from the Server

                  "Jochen Daum" <jochen.daum@ca ns.co.nz> wrote in message
                  news:ek07nvc6fj kp4v7vhakc2ss4f n4m1i2chm@4ax.c om...[color=blue]
                  > Hi Philo![/color]
                  [color=blue]
                  > Its really a question for comp.lang.javas cript and I actually asked it
                  > there 3 weeks ago. Short:
                  >
                  > - Use an iframe or different frame
                  > - Reload the frame with javascript and have a javascript array there.
                  > - copy it over into your select-box with javascript[/color]

                  Our original scheme had been to use a hidden frame, but I was looking for an
                  alternative. Our live support app was clearly not doing it that way, so I
                  was trying to figure out how they were.

                  I did find something that looks promising on another branch of this thread.


                  Comment

                  • Philo Del Middleston

                    #10
                    Re: Dynamically Refreshing a DIV or other control from the Server

                    I managed to get this tecnique working with my APP, and it's a very nice
                    trick. I'm pleased to know that I now have a solution that will work both on
                    the web and from my hosted browser control without resorting to
                    window.external , hidden frames, or any other kind of weird crap.

                    I found one other article that walks you through the same technique one step
                    at a time - it helped me identify a few problems that I had in my
                    implementation and get the thing running:


                    "Philo Del Middleston" <bitbucket@sobr anisoft.com> wrote in message
                    news:iKJcb.2271 5$iO.1120@bigne ws5.bellsouth.n et...[color=blue]
                    > "Andy Hassall" <andy@andyh.co. uk> wrote in message
                    > news:08p6nv0fif bdpvn4hunktqof1 1ssvfn0p1@4ax.c om...[color=green]
                    > > On Thu, 25 Sep 2003 17:52:44 -0400, "Philo Del Middleston"
                    > > <bitbucket@sobr anisoft.com> wrote:
                    > >[/color]
                    >[color=green]
                    > > (My reply was overly brief as it looked like it was going offtopic)[/color]
                    >
                    > Well, I knew that this live support product was pulling the data out with
                    > PHP, so this seemed like the right place to go. I knew I could get the[/color]
                    data[color=blue]
                    > into the document with Javascript, but getting the data looked like it was
                    > going to be a trick. Brief as your answer was, you got me headed in the
                    > right direction. I'll probably give this a shot tonight or tomorrow and[/color]
                    I'll[color=blue]
                    > report back with my results.
                    >
                    >[/color]


                    Comment

                    • Philo Del Middleston

                      #11
                      Re: Dynamically Refreshing a DIV or other control from the Server

                      I just noticed that the URL got munged. Here it is again:



                      Someone pointed out to me that this article missed the trick to avoid
                      caching by appending the date to the end of the script.src value as a GET
                      argument, so watch out for that.

                      "Philo Del Middleston" <bitbucket@sobr anisoft.com> wrote in message
                      news:rkYdb.1063 7$T65.6562@bign ews4.bellsouth. net...[color=blue]
                      > I managed to get this tecnique working with my APP, and it's a very nice
                      > trick. I'm pleased to know that I now have a solution that will work both[/color]
                      on[color=blue]
                      > the web and from my hosted browser control without resorting to
                      > window.external , hidden frames, or any other kind of weird crap.
                      >
                      > I found one other article that walks you through the same technique one[/color]
                      step[color=blue]
                      > at a time - it helped me identify a few problems that I had in my
                      > implementation and get the thing running:
                      > http://www.dhtmlcentral.com/tutoria...rials.asp?id=11
                      >
                      > "Philo Del Middleston" <bitbucket@sobr anisoft.com> wrote in message
                      > news:iKJcb.2271 5$iO.1120@bigne ws5.bellsouth.n et...[color=green]
                      > > "Andy Hassall" <andy@andyh.co. uk> wrote in message
                      > > news:08p6nv0fif bdpvn4hunktqof1 1ssvfn0p1@4ax.c om...[color=darkred]
                      > > > On Thu, 25 Sep 2003 17:52:44 -0400, "Philo Del Middleston"
                      > > > <bitbucket@sobr anisoft.com> wrote:
                      > > >[/color]
                      > >[color=darkred]
                      > > > (My reply was overly brief as it looked like it was going offtopic)[/color]
                      > >
                      > > Well, I knew that this live support product was pulling the data out[/color][/color]
                      with[color=blue][color=green]
                      > > PHP, so this seemed like the right place to go. I knew I could get the[/color]
                      > data[color=green]
                      > > into the document with Javascript, but getting the data looked like it[/color][/color]
                      was[color=blue][color=green]
                      > > going to be a trick. Brief as your answer was, you got me headed in the
                      > > right direction. I'll probably give this a shot tonight or tomorrow and[/color]
                      > I'll[color=green]
                      > > report back with my results.
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      Working...