473,378 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

change layout in two div at the same time

vikas251074
198 100+
I am using AJAX

Expand|Select|Wrap|Line Numbers
  1. function log2(str){
  2.   xmlHttp=GetXmlHttpObject();
  3.   if (xmlHttp==null) {
  4.     alert ("Your browser does not support AJAX!");
  5.     return;
  6.   } 
  7.   var url="checkpss.asp?q="+str+"&sid="+Math.random();
  8.   xmlHttp.onreadystatechange=stateChanged1;
  9.   xmlHttp.open("GET",url,true);
  10.   xmlHttp.send(null);
  11. }
  12.  
  13. function stateChanged1() { 
  14.   if (xmlHttp.readyState==4) {
  15.     document.getElementById("navBar1").innerHTML=xmlHttp.responseText;
  16.   }
  17. }
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
Jun 26 '08 #1

✓ answered by hsriat

When login in successful, call the ajax function again in the onreadystatechange of the first login function which would update the other divs.

31 3705
hsriat
1,654 Expert 1GB
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.
Jun 26 '08 #2
vikas251074
198 100+
Yes you are right.
But I don't know how to tokenize and split the data at the server end?

Thanks and regards,
Vikas
Jun 26 '08 #3
acoder
16,027 Expert Mod 8TB
No, you use a unique delimiter on the server-side and split on the client-side, e.g. the string "test||test2" can be split using javascript:
Expand|Select|Wrap|Line Numbers
  1. var resp = xmlHttp.responseText;
  2. respArr = resp.split("||");
  3. // now respArr[0] contains "test" and respArr[1] contains "test2"...
Jun 26 '08 #4
vikas251074
198 100+
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'
Expand|Select|Wrap|Line Numbers
  1. <%
  2. set conn = server.createobject("ADODB.Connection")
  3. conn.open "Provider=MSDAORA.1; dsn=ipis; password=ipis; user id=ipis; data source=isap2000; persist security into=true"
  4. set rs = server.createobject("ADODB.Recordset")
  5. set rs = conn.execute("select empno, empname from hba_empmast where empno="&trim(session("userid1")))
  6. if rs.eof then
  7.   response.write("Invalid Password")
  8. else
  9.   if trim(rs("empno"))=trim(request.querystring("q")) then
  10.     session("empname") = rs("empname")
  11. %>
  12.     <!--#include file="usersidebar.asp"-->
  13. <%    
  14.   else
  15.     response.write("Invalid Password")
  16.   end if
  17. end if
  18. %>
Using this code, the content of 'usersidebar.asp' is written in div 'navbar1'. Now I want to write the content of 'newsheadlines.asp', 'birthdaywish.asp' in another div 'detail'. How can I parse this? This is the problem I am facing?

Thanks and regards,
Vikas
Jun 27 '08 #5
acoder
16,027 Expert Mod 8TB
Oh, if it's another ASP page, just make another Ajax request instead. Easy and simple.
Jun 27 '08 #6
vikas251074
198 100+
Umm? I don't understand.
Jun 27 '08 #7
hsriat
1,654 Expert 1GB
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 onreadystatechange function so that it could know to which div the content is to be added when response text is received.
Jun 27 '08 #8
vikas251074
198 100+
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.


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 onreadystatechange 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?
Jun 27 '08 #9
hsriat
1,654 Expert 1GB
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?
Expand|Select|Wrap|Line Numbers
  1. function log2(str, divId){
  2.   xmlHttp=GetXmlHttpObject();
  3.   if (xmlHttp==null) {
  4.     alert ("Your browser does not support AJAX!");
  5.     return;
  6.   }
  7.   var url;
  8.   if (divId == "div1") url = "page1.asp";
  9.   else if (divId == "div2") url = "page2.asp";
  10.   else url = "page3.asp";
  11.   url += "?q="+str+"&sid="+Math.random();
  12.   xmlHttp.onreadystatechange = function () { stateChanged1(divId);};
  13.   xmlHttp.open("GET",url,true);
  14.   xmlHttp.send(null);
  15. }
  16.  
  17. function stateChanged1(divId) { 
  18.   if (xmlHttp.readyState==4) {
  19.     document.getElementById(divId).innerHTML = xmlHttp.responseText;
  20.   }
Jun 27 '08 #10
vikas251074
198 100+
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
Jun 27 '08 #11
acoder
16,027 Expert Mod 8TB
Alternatively, pass the URL as another parameter to the function (and remove the var url; line).
Jun 27 '08 #12
acoder
16,027 Expert Mod 8TB
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.
Jun 27 '08 #13
hsriat
1,654 Expert 1GB
I have not checked it now, but I hopes this will not work.
Keeps your hopes high, dude!
Jun 27 '08 #14
vikas251074
198 100+
What to write in line no.4 where function log2 is called?

Expand|Select|Wrap|Line Numbers
  1. <table> 
  2.   <tr>
  3.     <td><a href="#">Forgot Password?</a></td>
  4.     <td><input type="button" style="width:65px " value="Go" onclick="log2(document.myform.passwd.value);"/></td>
  5.   </tr>
  6. </table>
Jun 28 '08 #15
hsriat
1,654 Expert 1GB
What to write in line no.4 where function log2 is called?

Expand|Select|Wrap|Line Numbers
  1. <table> 
  2.   <tr>
  3.     <td><a href="#">Forgot Password?</a></td>
  4.     <td><input type="button" style="width:65px " value="Go" onclick="log2(document.myform.passwd.value);"/></td>
  5.   </tr>
  6. </table>
log2(document.myform.passwd.value, 'id_of_the_div_you_want_to_add_content_into');
Jun 28 '08 #16
vikas251074
198 100+
I am very confused now. I am getting error in different line than I suppose.

I am getting error in line no. 72. Error 'Object Expected'.
The code is given below and line no. is correct.

Thanks and regards,
Vikas

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Indian Oil Corporation Limited, Barauni Refinery</title>
  5. <script type="text/javascript">
  6. var xmlHttp
  7.  
  8. function userid2(str){
  9.   xmlHttp=GetXmlHttpObject();
  10.   if (xmlHttp==null) {
  11.     alert ("Your browser does not support AJAX!");
  12.     return;
  13.   } 
  14.   var url="checkuser.asp?q="+str+"&sid="+Math.random();
  15.   xmlHttp.onreadystatechange=stateChanged;
  16.   xmlHttp.open("GET",url,true);
  17.   xmlHttp.send(null);
  18. }
  19.  
  20. function stateChanged() { 
  21.   if (xmlHttp.readyState==4) {
  22.     document.getElementById("message").innerHTML=xmlHttp.responseText;
  23.   }
  24. }
  25.  
  26. function login2(str, divID){
  27.   xmlHttp=GetXmlHttpObject();
  28.   if (xmlHttp==null) {
  29.     alert ("Your browser does not support AJAX!");
  30.     return;
  31.   } 
  32.   var url
  33.   if(divID=='navBar1') url='checkpasswd.asp';
  34.   else (divID=='content') url='checkpasswd1.asp';
  35.   url=url+"?q="+str+"&sid="+Math.random();
  36.   xmlHttp.onreadystatechange=function(){stateChanged1(divID);};
  37.   xmlHttp.open("GET",url,true);
  38.   xmlHttp.send(null);
  39. }
  40.  
  41. function stateChanged1(divID) { 
  42.   if (xmlHttp.readyState==4) {
  43.     document.getElementById(divID).innerHTML=xmlHttp.responseText;
  44.   }
  45. }
  46.  
  47. function GetXmlHttpObject(){
  48.   var xmlHttp=null;
  49.   try { xmlHttp=new XMLHttpRequest(); }   // Firefox, Opera 8.0+, Safari
  50.   catch (e){ 
  51.     try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}   // Internet Explorer
  52.     catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
  53.   }
  54.   return xmlHttp;
  55. }
  56.  
  57. </script>
  58. </head>
  59. <body onload="document.myform.userid1.focus();"> 
  60. <form name="myform" action="main.asp" method="post"> 
  61. <div id="content" style="position:absolute; left:2px; top:125px; width:500px ">   
  62.   <div class="login1" style="position:relative; left:2px; width:175px"> 
  63.     <table border="1" cellpadding="0" cellspacing="0">
  64.     <tr>
  65.       <td bgcolor="#CCCCCC"><h3>Employee Login</h3></td>
  66.     </tr>
  67.     <tr>
  68.       <td>
  69.         <table>
  70.           <tr>
  71.             <td align="right">Login :</td>
  72.             <td><input type="text" name="userid1" id="userid1" style="width:100px " onblur="userid2(this.value);"/></td>
  73.           </tr>
  74.           <tr>
  75.             <td align="right">Password :</td>
  76.             <td><input type="password" name="passwd" style="width:100px "/></td>
  77.           </tr>
  78.         </table>
  79.       </td>
  80.     </tr>
  81.     <tr>
  82.       <td>
  83.         <table> 
  84.           <tr>
  85.             <td><a href="#">Forgot Password?</a></td>
  86.             <td><input type="button" style="width:65px " value="Go" onclick="login2(document.myform.passwd.value,'content');"/></td>
  87.           </tr>
  88.        </table>
  89.       </td>
  90.     </tr>
  91.     <tr>
  92.       <td>
  93.         <table>
  94.           <tr>
  95.             <td><p id="message" style="width:175px ">Enter user id and password</p></td>
  96.           </tr>
  97.         </table>
  98.       </td>
  99.     </tr>
  100.   </table>
  101.   </div> 
  102. <br>
  103.   <h2 id="pageName">Main Page</h2> 
  104.   <div class="feature"> 
  105.     <h1>Surfing the intranet </h1> 
  106.     <p>
  107.     This is a comprehensive information website on Indian Oil Corporation Limited and specially 
  108.     dedicated to Barauni Refinery.
  109.     </p>
  110.   </div> 
  111.   <div class="story"> 
  112.     <h3>Story Title</h3> 
  113.     <p> 
  114.     Barauni Refinery was built in collaboration with Russia and Romania. Situated 125 kilometeres 
  115.     from Patna, it was built with an initial cost of Rs 49.40 crore. Barauni Refinery was 
  116.     commissioned in 1964 with a refining capacity of 1 Million Metric Tonnes per Annum (MMTPA) 
  117.     and it was dedicated to the Nation by the then Union Minister for Petroleum, Prof. Humayun 
  118.     Kabir in January 1965. After de-bottlenecking, revamping and expansion project, it's capacity 
  119.     today is 6 MMTPA. Matching secondary processing facilities such Resid Fluidised Catalytic 
  120.     Cracker (RFCC), Diesel Hydrotreating (DHDT), Sulphur Recovery Unit (SRU) have been added. 
  121.     These state of the art eco-friendly technologies have enabled the refinery to produce 
  122.     environment- friendly green fuels complying with international standards.
  123.     </p>
  124.     <p>
  125.     Barauni Refinery was initially designed to process low sulphur crude oil (sweet crude) of 
  126.     Assam. After establishment of other refineries in the Northeast, Assam crude is unavailable 
  127.     for Barauni . Hence, sweet crude is being sourced from African, South East Asian and 
  128.     Middle East countries like Nigeria, Iraq & Malaysia. The crude is brought up to Haldia by 
  129.     Very Large Crude Carriers (VLCCs) from where it is pumped through pipeline to Barauni. 
  130.     With various revamps and expansion project at Barauni Refinery, capability for processing 
  131.     high -sulphur crude has been added — high-sulphur crude oil (sour crude) is cheaper than 
  132.     low sulphur crudes — thereby increasing not only the capacity but also the profitability 
  133.     of the refinery.
  134.     </p> 
  135.   </div> 
  136. </div> 
  137. <!--end content --> 
  138. <br> 
  139. <div id="navBar1" style="position:absolute; left:800px; top:125px; width:200px ">
  140. <% if session("userid1")="" then %>
  141.   <!--#include file="sidebar.asp"--> 
  142. <% else %>
  143.   <!--#include file="usersidebar.asp"--> 
  144. <% end  if %>
  145. </div>
  146. </form>
  147. </body>
  148. </html>
Jun 28 '08 #17
hsriat
1,654 Expert 1GB
Add a value attrubute to the input.

I would suggest you to test your program in Firefox. IE would never tell the exact line of the code and exact error details. Such error messages are too vague.

Use Firefox, there you can find the Error console in tools. Check out your error and you would find what exactly was the problem.
Jun 28 '08 #18
vikas251074
198 100+
I would suggest you to test your program in Firefox.

I am working in my office where I don't have firefox.
Jun 28 '08 #19
vikas251074
198 100+
Add a value attrubute to the input.
Where to add value attribute - line no. 72 or 76. and what value has to be assigned.

Like this ?

Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" name="userid1" id="userid1" style="width:100px " value="" onblur="userid2(this.value);"/></td>
  2. <td><input type="password" name="passwd" style="width:100px " value=""/></td>
Jun 28 '08 #20
hsriat
1,654 Expert 1GB
I am working in my office where I don't have firefox.
That is really sad that your employer is working for IOCL and still it doesn't provide the developers with all the available browsers so that they could build a cross-browser web application.

Well that's not a solution for your problem. I see that on line 34, you have written
Expand|Select|Wrap|Line Numbers
  1. else (divID=='content') url='checkpasswd1.asp';
either remove the condition or make it else if
Jun 28 '08 #21
hsriat
1,654 Expert 1GB
Where to add value attribute - line no. 72 or 76. and what value has to be assigned.

Like this ?

Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" name="userid1" id="userid1" style="width:100px " value="" onblur="userid2(this.value);"/></td>
  2. <td><input type="password" name="passwd" style="width:100px " value=""/></td>
In the first one. But that should not do anything wrong. But again, I ain't sure about IE.
Jun 28 '08 #22
vikas251074
198 100+
Action : Here any one div is modified not both. ???


Let me explain you what I need. I have userid password screen. If user id and password is verified then it should display content in two or more div at the same time.
Jun 28 '08 #23
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.
Hello, May I ask a question?
Jun 28 '08 #24
hsriat
1,654 Expert 1GB
Hello, May I ask a question?
Of course!!


You may ask it in a new thread here>> http://bytes.com/forum/newthread.php?do=newthread&f=149
Jun 28 '08 #25
hsriat
1,654 Expert 1GB
Action : Here any one div is modified not both. ???


Let me explain you what I need. I have userid password screen. If user id and password is verified then it should display content in two or more div at the same time.
I could not understand your requirements at all. It would be better if you explain it properly step by step.
Jun 28 '08 #26
vikas251074
198 100+
I could not understand your requirements at all. It would be better if you explain it properly step by step.
Let me explain you.

I have first div for displaying heading information about company.
second div for displaying different option listed in right hand side of screen
third div for displaying user id password screen.
fourth div for displaying few text about company.
fifth div for displaying few text about anything.


Now when user login successfully, then all div except first div should change content using AJAX method.
second div should contain user specific option.
third div should contain list of employees having birthday today.
fourth div should contain something
fifth div should contain some other thing.

Currently I am able to change only one div i.e. second, what should be done to change rest div (third, fourth, fifth div)?
Jun 28 '08 #27
hsriat
1,654 Expert 1GB
When login in successful, call the ajax function again in the onreadystatechange of the first login function which would update the other divs.
Jun 28 '08 #28
acoder
16,027 Expert Mod 8TB
I am working in my office where I don't have firefox.
Bah! That's no excuse ;)

Tell your employer that you need to support other browsers too - possibly up to a quarter of your visitors or more in some countries.
Jun 28 '08 #29
vikas251074
198 100+
When login in successful, call the ajax function again in the onreadystatechange of the first login function which would update the other divs.
Can u tell me how to do this?
Jun 30 '08 #30
vikas251074
198 100+
Bah! That's no excuse ;)

Tell your employer that you need to support other browsers too - possibly up to a quarter of your visitors or more in some countries.
There is no need because this is limited to working employees only that too in local area where over 1000 employee will use
Jun 30 '08 #31
hsriat
1,654 Expert 1GB
There is no need because this is limited to working employees only that too in local area where over 1000 employee will use
I wonder why people don't understand that IE is the worst thing that happened in the world of computing.

There is really lack of knowledge.

Any how,
in that onreadystatechange, if divId is content, call the log2 function again with divId as the other value.
Jun 30 '08 #32

Sign in to post your reply or Sign up for a free account.

Similar topics

39
by: Zak McGregor | last post by:
Hi all Are there any good solutions to aligning form field names and input boxes without resorting to tables? I am struggling to do this nicely at the moment. Thanks Ciao Zak
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
9
by: Peter | last post by:
Hi at all, how can I do to make a css file to change automatically the text size of the text that is into a table relatively the screen size? I.E. if the screen is 800 x I want the text...
11
by: Unknown User | last post by:
I've been using CSS layout (Tableless) for some time now, and I think it's the best way to create a page, but I've been quite concerned about the raising cost vs. fierce competition in the...
2
by: L Mehl | last post by:
Hello -- Is there a way to configure 2000 so it will save a view layout after I change it in the diagram pane? Thanks for any help. Larry Mehl
11
by: SarahMarsden | last post by:
I'm new to Dreamweaver (using MX 2004). I have a 2 row 3 column table. I have set each column to 200 pixels. The second row I have merged into one cell. When I enter text (or anything else) into...
0
by: Christian | last post by:
Hi, I try to change the position of a WebUserControl on my WEbform (layout is set to GridLayout) by changing the absolute position in the html-code but it does not work. When I change the...
1
by: Kenneth Keeley | last post by:
Hi, Can I change the layout and style of a TemplateColumn at run time to display information differently base on one of the fields of data. If the item is labled as urgent the title my appear Red...
13
by: shapper | last post by:
Hello, I see in many web sites, such in Google, inputs that when i click on them to write something they change their style. This works both in Firefox and IE (These are the ones with which I...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.