Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 27th, 2005, 05:54 PM
Authorized User
Join Date: Dec 2004
Location: Chesterfield, MO, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default AJAX and Empty Fields

I'm writing an AJAX application that retrieves a dynamically created XML file from a webserver (the xml is created using PHP). I've got the application working great except when the field is empty. In particular, the following XML

<?xml version="1">
  <event>Something is happening</event>

As you can see, the time field is empty and when I run the javascript to parse the returned data, I get a javascript error.

I'm using the following javascript to parse the file
function parseXML() {
  var theXML = xmlHttpReq.responseXML;
  var date= theXML.getElementsByTagName('date')[0].firstChild.data;
  var time = theXML.getElementsByTagName('time')[0].firstChild.data;
  var event = theXML.getElementsByTagName('event')[0].firstChild.data;


The error happens when I try to assign the value to the time variable. The firefox javascript console tells me that firstChild has no properties.

My question: how do I check to see if there is data present? I've tried several different things like
if(typeof(theXML.getElementsByTagName('time')[0].firstChild) != "undefined")
But it's just not working.

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old December 29th, 2005, 05:16 PM
Registered User
Join Date: Dec 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Try this:

if( theXML.getElementsByTagName('time')[0].firstChild ){
    var time = theXML.getElementsByTagName('time')[0].firstChild.data;

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count all empty fields in Biztalk biztalkuser Biztalk 0 January 4th, 2006 07:37 AM
How to check for empty fields in a form. crmpicco Javascript How-To 7 February 15th, 2005 10:38 AM
empty fields not hidden anymore (php/mySQL) jasmin Beginning PHP 1 January 17th, 2005 12:42 PM
Empty Fields priority05 Access ASP 3 January 10th, 2005 04:40 PM
Subreport for CR9 giving empty fields in reports yblee Crystal Reports 0 August 18th, 2004 10:24 PM

All times are GMT -4. The time now is 11:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.