473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DIV tags don't show text from onblur

31 New Member
I'm totally lost! I've been trying for several days to make Onblur fill in the city, state after the user inputs inside a textbox a 5 digit zip code, from the the zip, city, state text boxes I want to extract the info and pu it in a separate line like this:
a) user puts a zipcode:95051
b) Onblur fills in city and state
c) a new line in the same page showing ex.
Support Services
SantaClara,CA 95051

I have a test page loaded with all the code here: http://www.echildcarem anagement.com/prototype/step6.html

The HTML code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>ZIP Code to City and State using XmlHttpRequest</title>
  5. <script language="javascript"  type="text/javascript">
  6. var url = "CityState.php?param="; // The server-side script
  7. function handleHttpResponse() {
  8.   if (http.readyState == 4) {
  9.     // Split the comma delimited response into an array
  10.     results = http.responseText.split(",");
  11.     document.getElementById('city').value = results[0];
  12.       document.getElementById('state').value = results[1];
  13.       document.getElementById('areacode').value = results[2];
  14.       document.getElementById('zip').firstChild.nodeValue = city + ', ' + state;
  15.       document.getElementById('zip1').firstChild.nodeValue = zip;
  16.   }
  17. }
  18. function updateCityState() {
  19.   var zipValue = document.getElementById("zip").value;
  20.   http.open("GET", url + escape(zipValue), true);
  21.   http.onreadystatechange = handleHttpResponse;
  22.   http.send(null);
  23. }
  24. function getHTTPObject() {
  25.   var xmlhttp;
  26.   /*@cc_on
  27.   @if (@_jscript_version >= 5)
  28.     try {
  29.       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  30.     } catch (e) {
  31.       try {
  32.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  33.       } catch (E) {
  34.         xmlhttp = false;
  35.       }
  36.     }
  37.   @else
  38.   xmlhttp = false;
  39.   @end @*/
  40.   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  41.     try {
  42.       xmlhttp = new XMLHttpRequest();
  43.     } catch (e) {
  44.       xmlhttp = false;
  45.     }
  46.   }
  47.   return xmlhttp;
  48. }
  49. var http = getHTTPObject(); // We create the HTTP Object
  50. </script>
  51. <style type="text/css">
  52. <!--
  53. .style1 {
  54.     font-size: 16px;
  55.     font-weight: bold;
  56.     font-style: italic;
  57. }
  58. -->
  59. </style>
  60. </head>
  61. <body>
  62. <p>&nbsp;</p>
  63. <p>&nbsp;</p>
  64. <p class="style1"><fieldset>
  65. <legend>Computer information:</legend>
  66. <legend><div id="city1"></div></legend>
  67. <legend>
  68. <div id="state1"></div>
  69. </legend>
  70. <legend>
  71. </legend>
  72. </fieldset></p>
  73.  
  74. <p class="style1">Schedule your services now!</p>
  75. <p>&nbsp;</p>
  76. <p>&nbsp;</p>
  77. <p>&nbsp;</p>
  78. <p>&nbsp; </p>
  79. <form action="post">
  80.   <p>ZIP code:
  81.     <input type="text" size="5" name="zip" id="zip1" onblur="updateCityState();" />
  82.   </p>
  83.   City:
  84.   <input type="text" name="city" id="city1" />
  85.   State:
  86.   <input type="text" size="2" name="state" id="state1" />
  87. </form>
  88. </body>
  89. </html>
Thanks for your help!

Ed
PS pbmods has been helping, somehow it was working before now is not working? am I missing something inside the DIV tags?
Jul 23 '07 #1
26 2253
gits
5,390 Recognized Expert Moderator Expert
hi ...

the only id of a div (where you want the output?) that you have in your document is 'city1' but in handleHttpRespo nse you try to getElementById( 'city') etc. so you will get an error that your elements are not found ... put all divs with the correct ids in your document, or outcomment all lines that try to get an unavailable id for testing purposes ... so: your problem are the ids! ;)

kind regards
Jul 23 '07 #2
edwire
31 New Member
hi ...

the only id of a div (where you want the output?) that you have in your document is 'city1' but in handleHttpRespo nse you try to getElementById( 'city') etc. so you will get an error that your elements are not found ... put all divs with the correct ids in your document, or outcomment all lines that try to get an unavailable id for testing purposes ... so: your problem are the ids! ;)

kind regards
But I'm trying to get zip, city and state info inside the textboxes from there I want to extract that information and put it in another line, if I was to remove handleHttpRespo nse you try to getElementById( 'city') then nothing works! on the DIV all I want in there is to be able to have the output from the city, state and zipcode once onblur updates the textbox, but I wan to keep the information also inside the textboxes.. I hope this is clear enough?

All I need to be able to show is when someone enters a zip number the city and state with Onblur which it does! from there i want to be able to put it somewhere like this: Support Services one line, Santa Clara, CA 95051 seconde line, call 408-445-4573 third line.

Thanks a lot!

Ed
Jul 23 '07 #3
epots9
1,351 Recognized Expert Top Contributor
with some help from firefox i was able to get your code working...fixes :

u are using the command "getElementById " but your using the name attribute instead of the id.

ie:
[HTML]<input type="text" size="2" name="state" id="state1" />[/HTML]
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("state").value = results[1];
  2. //this line won't find anything, gives an error.
  3.  
in your html code, make the id and name have the same value, cuz some browsers don't support the attribute id, so at least this way they are the same value so the way u call them would be different.

[HTML]<input type="text" size="2" name="state" id="state" />[/HTML]

also,
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("areacode").value = results[2];
  2.  
does not exist, so it throws an error, comment it out or add a textbox with areacode as its id.

correct these errors and test it out, if there are still any problems repost the new version to that site u have above and we'll take a look.

if all is working, post back to tell us.

good luck
Jul 23 '07 #4
epots9
1,351 Recognized Expert Top Contributor
**double post....my bad
Jul 23 '07 #5
edwire
31 New Member
with some help from firefox i was able to get your code working...fixes :

u are using the command "getElementById " but your using the name attribute instead of the id.

ie:
[HTML]<input type="text" size="2" name="state" id="state1" />[/HTML]
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("state").value = results[1];
  2. //this line won't find anything, gives an error.
  3.  
in your html code, make the id and name have the same value, cuz some browsers don't support the attribute id, so at least this way they are the same value so the way u call them would be different.

[HTML]<input type="text" size="2" name="state" id="state" />[/HTML]

also,
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("areacode").value = results[2];
  2.  
does not exist, so it throws an error, comment it out or add a textbox with areacode as its id.

correct these errors and test it out, if there are still any problems repost the new version to that site u have above and we'll take a look.

if all is working, post back to tell us.

good luck
Here is the HTML with changes:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>ZIP Code to City and State using XmlHttpRequest</title>
  5. <script language="javascript"  type="text/javascript">
  6. var url = "CityState.php?param="; // The server-side script
  7. function handleHttpResponse() {
  8.   if (http.readyState == 4) {
  9.     // Split the comma delimited response into an array
  10.     results = http.responseText.split(",");
  11.     document.getElementById('city').value = results[0];
  12.       document.getElementById('state').value = results[1];
  13.       document.getElementById('zip').firstChild.nodeValue = city + ', ' + state;
  14.       document.getElementById('zip1').firstChild.nodeValue = zip;
  15.   }
  16. }
  17. function updateCityState() {
  18.   var zipValue = document.getElementById("zip").value;
  19.   http.open("GET", url + escape(zipValue), true);
  20.   http.onreadystatechange = handleHttpResponse;
  21.   http.send(null);
  22. }
  23. function getHTTPObject() {
  24.   var xmlhttp;
  25.   /*@cc_on
  26.   @if (@_jscript_version >= 5)
  27.     try {
  28.       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  29.     } catch (e) {
  30.       try {
  31.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  32.       } catch (E) {
  33.         xmlhttp = false;
  34.       }
  35.     }
  36.   @else
  37.   xmlhttp = false;
  38.   @end @*/
  39.   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  40.     try {
  41.       xmlhttp = new XMLHttpRequest();
  42.     } catch (e) {
  43.       xmlhttp = false;
  44.     }
  45.   }
  46.   return xmlhttp;
  47. }
  48. var http = getHTTPObject(); // We create the HTTP Object
  49. </script>
  50. <style type="text/css">
  51. <!--
  52. .style1 {
  53.     font-size: 16px;
  54.     font-weight: bold;
  55.     font-style: italic;
  56. }
  57. -->
  58. </style>
  59. </head>
  60. <body>
  61. <p>&nbsp;</p>
  62. <p>&nbsp;</p>
  63. <p class="style1"><fieldset>
  64. <legend>Computer information:</legend>
  65. <legend><div id="city1"></div></legend>
  66. <legend>
  67. <div id="state1"></div>
  68. </legend>
  69. <legend>
  70. </legend>
  71. </fieldset></p>
  72.  
  73. <p class="style1">Schedule your services now!</p>
  74. <p>&nbsp;</p>
  75. <p>&nbsp;</p>
  76. <p>&nbsp;</p>
  77. <p>&nbsp; </p>
  78. <form action="post">
  79.   <p>ZIP code:
  80.     <input type="text" size="5" name="zip" id="zip" onblur="updateCityState();" />
  81.   </p>
  82.   City:
  83.   <input type="text" name="city" id="city" />
  84.   State:
  85.   <input type="text" size="2" name="state" id="state" />
  86. </form>
  87. </body>
  88. </html>
This is the test webpage: http://www.echildcarem anagement.com/prototype/step6.html with all the changes I'm able to show with Onblur the city, state but under " Computer Information: I want to read in line one: state, city and zip code (Santa Clara, CA 95051), in line 2: I want to show a telephone number( North Call 408-458-4855). When I input the zip code all I get now is the update inside the text boxes for city and state and NOT the DIV info? am I missing something? the more I read the more I confuse myself.

epots thanks for your help, this is driving me insane!

Ed
Jul 23 '07 #6
epots9
1,351 Recognized Expert Top Contributor
modify this:
Expand|Select|Wrap|Line Numbers
  1. function handleHttpResponse() {
  2.   if (http.readyState == 4) {
  3.     // Split the comma delimited response into an array
  4.     results = http.responseText.split(",");
  5.     var city = document.getElementById('city').value = results[0];
  6.       var state = document.getElementById('state').value = results[1];
  7.       document.getElementById('city1').innerHTML = city + ", " + state + ", " + document.getElementById('zip').value;
  8.        document.getElementById('state1').innerHTML = "North Call 408-458-4855";
  9.   }
  10. }
  11.  
u have to use innerHTML to write into a div tag.

good luck
Jul 23 '07 #7
edwire
31 New Member
modify this:
Expand|Select|Wrap|Line Numbers
  1. function handleHttpResponse() {
  2.   if (http.readyState == 4) {
  3.     // Split the comma delimited response into an array
  4.     results = http.responseText.split(",");
  5.     var city = document.getElementById('city').value = results[0];
  6.       var state = document.getElementById('state').value = results[1];
  7.       document.getElementById('city1').innerHTML = city + ", " + state + ", " + document.getElementById('zip').value;
  8.        document.getElementById('state1').innerHTML = "North Call 408-458-4855";
  9.   }
  10. }
  11.  
u have to use innerHTML to write into a div tag.

good luck
Hey epots, thanks for your help! I've updated with the new tags and still don't work? is there anything missing in the DIV tags? I've just can't figure this out?

here is the new HTML and script code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>ZIP Code to City and State using XmlHttpRequest</title>
  5. <script language="javascript"  type="text/javascript">
  6. var url = "CityState.php?param="; // The server-side script
  7. function handleHttpResponse() {
  8.   if (http.readyState == 4) {
  9.     // Split the comma delimited response into an array
  10.     results = http.responseText.split(",");
  11.     document.getElementById('city').value = results[0];
  12.       document.getElementById('state').value = results[1];
  13.       document.getElementById('zip').firstChild.nodeValue = city + ', ' + state;
  14.       document.getElementById('city1').innerHTML = city + ', ' + state;
  15.       document.getElementById('zip').value;
  16.       document.getElementById('state1').innerHTML = "North Call 408-458-4855";
  17.   }
  18. }
  19. function updateCityState() {
  20.   var zipValue = document.getElementById("zip").value;
  21.   http.open("GET", url + escape(zipValue), true);
  22.   http.onreadystatechange = handleHttpResponse;
  23.   http.send(null);
  24. }
  25. function getHTTPObject() {
  26.   var xmlhttp;
  27.   /*@cc_on
  28.   @if (@_jscript_version >= 5)
  29.     try {
  30.       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  31.     } catch (e) {
  32.       try {
  33.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  34.       } catch (E) {
  35.         xmlhttp = false;
  36.       }
  37.     }
  38.   @else
  39.   xmlhttp = false;
  40.   @end @*/
  41.   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  42.     try {
  43.       xmlhttp = new XMLHttpRequest();
  44.     } catch (e) {
  45.       xmlhttp = false;
  46.     }
  47.   }
  48.   return xmlhttp;
  49. }
  50. var http = getHTTPObject(); // We create the HTTP Object
  51. </script>
  52. <style type="text/css">
  53. <!--
  54. .style1 {
  55.     font-size: 16px;
  56.     font-weight: bold;
  57.     font-style: italic;
  58. }
  59. -->
  60. </style>
  61. </head>
  62. <body>
  63. <p>&nbsp;</p>
  64. <p>&nbsp;</p>
  65. <p class="style1"><fieldset>
  66. <legend>Computer information:</legend>
  67. <legend><div id="city1"></div></legend>
  68. <legend>
  69. <div id="state1"></div>
  70. </legend>
  71. <legend>
  72. </legend>
  73. </fieldset></p>
  74.  
  75. <p class="style1">Schedule your services now!</p>
  76. <p>&nbsp;</p>
  77. <p>&nbsp;</p>
  78. <p>&nbsp;</p>
  79. <p>&nbsp; </p>
  80. <form action="post">
  81.   <p>ZIP code:
  82.     <input type="text" size="5" name="zip" id="zip" onblur="updateCityState();" />
  83.   </p>
  84.   City:
  85.   <input type="text" name="city" id="city" />
  86.   State:
  87.   <input type="text" size="2" name="state" id="state" />
  88. </form>
  89. </body>
  90. </html>
thank you!

Ed
Jul 23 '07 #8
edwire
31 New Member
epost9 sorry line 13 was edited from the code.

Ed
Jul 23 '07 #9
epots9
1,351 Recognized Expert Top Contributor
epost9 sorry line 13 was edited from the code.

Ed
are there any improvements?
Jul 23 '07 #10

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

Similar topics

7
1523
by: Abby Lee | last post by:
I have back to back text boxes used to create university account numbers. I'm actually creating them with a script so they can create as many account numbers as they need. <edited and cut down script> <input type="text" size="5" name="fund_1" onBlur="checkact(this)"> <input type="text" size="5" name="org_1" onBlur="checkact(this)">" ...
8
5735
by: Hostile17 | last post by:
Consider the following HTML. ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <title>Untitled</title>
2
1722
by: nikou_70 | last post by:
I have a page with one text box when I search name, return value such as (address, phone...) I show these value in the table but I want to show these in text box that I have in my page. <%@ Language=VBScript %> <%
4
8659
by: Dabbler | last post by:
Is there a way to mark the text in a TextBox control as selected so when the user types a new value the existing text is replaced? Thanks
10
3089
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a RegularExpressionValidator that will allow certain HTML tags: <a>, <b>, <blockquote>, <br>, <i>, <img>, <li>, <ol>, <p>, <quote>, <ul>
8
6385
by: Zytan | last post by:
I thought each XmlNodeType.Element has a matching XmlNodeType.EndElement. But, this does not occur when the XML file has the following: <example attr1="1" attr2="2" /> Even though this is syntactically the same as the following, which does show the EndElement: <example attr1="1" attr2="2">
7
1108
by: miladhatam | last post by:
hi friends i've built a page that should show first 150 chars of every of my topics but when i wanted to do this work with SubString() it included the tags of my field of my db and very bad viewing happend i want to retrieve rendered text without any tag ... please help me ...
17
1788
by: V S Rawat | last post by:
I joined this ng and tried to post my first message that had a small php code (HTML and all). my newsserver aioe.net rejected the post saying "HTML Tags". My message was in text format, not in html format, but it obviously had html tags. Now, a php or a perl/ cgi or a javascript ng is always going to had html tags in posted messages....
8
5127
by: azjudd | last post by:
Thank you in advance for your help on this one. I'm using named anchor tags on a FAQ page with questions listed at the top and answers below; a standard jump-to feature. However, anytime an anchor tag link is used, whether it be a question down to an answer or an answer back to the list of questions, I lose the banner div, a good portion of of...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.