change layout in two div at the same time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas251074
    New Member
    • Dec 2007
    • 198

    change layout in two div at the same time

    I am using AJAX

    Code:
    function log2(str){
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
      } 
      var url="checkpss.asp?q="+str+"&sid="+Math.random();
      xmlHttp.onreadystatechange=stateChanged1;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
    }
    
    function stateChanged1() { 
      if (xmlHttp.readyState==4) {
        [B]document.getElementById("navBar1").innerHTML=xmlHttp.responseText;[/B]
      }
    }
    I have a form in which 4 div is used. When a button is pressed, the above function is called. At present I am able to change content in one div by using above method. I want to change content one more div which is a seperate div. How can I do this?

    Thanks and regards,
    Vikas
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    I think you want to add different data to the different divs. If that's the case, tokenize the data at the server end. Split it into required parts at client side when received as responseText. Then add them in different divs.
    Or Use responseXML, and parse the XML at client side.

    Comment

    • vikas251074
      New Member
      • Dec 2007
      • 198

      #3
      Yes you are right.
      But I don't know how to tokenize and split the data at the server end?

      Thanks and regards,
      Vikas

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No, you use a unique delimiter on the server-side and split on the client-side, e.g. the string "test||test 2" can be split using JavaScript:
        [code=javascript]var resp = xmlHttp.respons eText;
        respArr = resp.split("||" );
        // now respArr[0] contains "test" and respArr[1] contains "test2"...[/code]

        Comment

        • vikas251074
          New Member
          • Dec 2007
          • 198

          #5
          As you know, I need to change in two div named 'navbar1' and 'detail'. I easily change content in 'navbar1' by using line no. 15 in code given in first posts. The change in content of div 'navbar1' is due to the code in 'checkpss.asp'.
          Code of 'checkpss.asp'
          Code:
          <%
          set conn = server.createobject("ADODB.Connection")
          conn.open "Provider=MSDAORA.1; dsn=ipis; password=ipis; user id=ipis; data source=isap2000; persist security into=true"
          set rs = server.createobject("ADODB.Recordset")
          set rs = conn.execute("select empno, empname from hba_empmast where empno="&trim(session("userid1")))
          if rs.eof then
            response.write("Invalid Password")
          else
            if trim(rs("empno"))=trim(request.querystring("q")) then
              session("empname") = rs("empname")
          %>
              <!--#include file="usersidebar.asp"-->
          <%	
            else
              response.write("Invalid Password")
            end if
          end if
          %>
          Using this code, the content of 'usersidebar.as p' is written in div 'navbar1'. Now I want to write the content of 'newsheadlines. asp', 'birthdaywish.a sp' in another div 'detail'. How can I parse this? This is the problem I am facing?

          Thanks and regards,
          Vikas

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Oh, if it's another ASP page, just make another Ajax request instead. Easy and simple.

            Comment

            • vikas251074
              New Member
              • Dec 2007
              • 198

              #7
              Umm? I don't understand.

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by vikas251074
                Umm? I don't understand.
                Pass another argument to your log2 function which would tell about which div is to be updated.
                Depending upon that second argument, decide the url from where you have to get the content from (using if-else or switch). Then pass that same argument to onreadystatecha nge function so that it could know to which div the content is to be added when response text is received.

                Comment

                • vikas251074
                  New Member
                  • Dec 2007
                  • 198

                  #9
                  Originally posted by hsriat
                  Pass another argument to your log2 function which would tell about which div is to be updated.
                  But here is only one argument. There is no other argument to pass. So why and which argument should I pass into log2 function.


                  Originally posted by hsriat
                  Depending upon that second argument, decide the url from where you have to get the content from (using if-else or switch). Then pass that same argument to onreadystatecha nge function so that it could know to which div the content is to be added when response text is received.
                  I can't understand how the second div could be modified?

                  Comment

                  • hsriat
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1653

                    #10
                    Originally posted by vikas251074
                    But here is only one argument. There is no other argument to pass. So why and which argument should I pass into log2 function.
                    I can't understand how the second div could be modified?
                    [CODE=javascript]function log2(str, divId){
                    xmlHttp=GetXmlH ttpObject();
                    if (xmlHttp==null) {
                    alert ("Your browser does not support AJAX!");
                    return;
                    }
                    var url;
                    if (divId == "div1") url = "page1.asp" ;
                    else if (divId == "div2") url = "page2.asp" ;
                    else url = "page3.asp" ;

                    url += "?q="+str+"&sid ="+Math.random( );
                    xmlHttp.onready statechange = function () { stateChanged1(d ivId);};
                    xmlHttp.open("G ET",url,true) ;
                    xmlHttp.send(nu ll);
                    }

                    function stateChanged1(divId) {
                    if (xmlHttp.readyS tate==4) {
                    document.getEle mentById(divId).innerHTML = xmlHttp.respons eText;
                    }[/CODE]

                    Comment

                    • vikas251074
                      New Member
                      • Dec 2007
                      • 198

                      #11
                      Here I think, any one div will be modified, which is being passed as a second argument. Because it is checking for only all div one by one and if it is one the div then that div is modified.
                      As you know this function is called after checking username and password. If correct then two div should be modifed.

                      I have not checked it now, but I hopes this will not work. Anyway I may check it first then report to you.

                      Thanks and regards,
                      Vikas

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Alternatively, pass the URL as another parameter to the function (and remove the var url; line).

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by vikas251074
                          Here I think, any one div will be modified, which is being passed as a second argument. Because it is checking for only all div one by one and if it is one the div then that div is modified.
                          As you know this function is called after checking username and password. If correct then two div should be modifed.
                          If you need to wait for the first request to be complete before making subsequent requests, then call the function when the readyState is 4 in the first request.

                          Comment

                          • hsriat
                            Recognized Expert Top Contributor
                            • Jan 2008
                            • 1653

                            #14
                            Originally posted by vikas251074
                            I have not checked it now, but I hopes this will not work.
                            Keeps your hopes high, dude!

                            Comment

                            • vikas251074
                              New Member
                              • Dec 2007
                              • 198

                              #15
                              What to write in line no.4 where function log2 is called?

                              Code:
                              <table> 
                                <tr>
                                  <td><a href="#">Forgot Password?</a></td>
                                  [B]<td><input type="button" style="width:65px " value="Go" onclick="log2(document.myform.passwd.value);"/></td>[/B]
                                </tr>
                              </table>

                              Comment

                              Working...