Loading ...
Sorry, an error occurred while loading the content.
 

Re: [JavaScript] script stops when an array element is empty

Expand Messages
  • David Smart
    JavaScript won t inherently stop on a blank item. You are going to need to show us at least your JS code, but probably a bit more of the page too. If,
    Message 1 of 9 , Jan 31, 2008
      JavaScript won't inherently stop on a blank item. You are going to need to
      show us at least your JS code, but probably a bit more of the page too.

      If, however, an event handler strikes a problem, it will probably close
      silently. You possibly need to be running the page in a debugging
      environment such as Arachnophilia.

      Regards, Dave S

      PS Diving into Ajax is not necessarily the best way to start learning JS.
      It'd be better, probably, to write some in a more traditional page first.

      ----- Original Message -----
      From: "wadesmart" <no_reply@yahoogroups.com>
      To: <JavaScript_Official@yahoogroups.com>
      Sent: Friday, February 01, 2008 8:12 AM
      Subject: [JavaScript] script stops when an array element is empty


      > Im totally new to JS so I got a book titled Building a Web Site with
      > Ajax and I went through the tutorials. I understand them enough in
      > their own environment but I moved on and attempted to apply them to my
      > own current needs.
      >
      > So I really just changed a few names and applied it to my form and it
      > seems to work great - until this small problem.
      >
      > Really quick, you type in the first few letters of the persons last
      > name and hit submit. The script accesses a mysql db through php and
      > extracts the data. Its posted back to the page either through php - if
      > there is no javascript ability or through ajax if there is.
      >
      > When I typed in "S" I have about 30 names that should be pulled up but
      > only 4 names are shown. The error console says that this has no
      > properties:
      >
      > a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
      >
      > Interestingly enough, I installed FireBug and it actually shows me
      > that the data returned from the php script HAS all the names in it
      > but, what is missing is the email address of a few people. We have
      > their first, last names, telephone and email address but not everyone
      > provided an email address. So Im assuming when this javascript comes
      > up against a blank email it just stops processing.
      >
      > My question is, what do you do when you still want the script to put
      > out what is there, even if it is empty?
      >
      > Wade
      >
      >
      >
      > Visit http://aiaiai.com for more groups to join
      > Yahoo! Groups Links
      >
      >
      >
    • wadesmart
      This is the search.js sheet. window.onload = init; function init() { var ajax = getXMLHttpRequestObject(); if (ajax) { if (document.getElementById( results )){
      Message 2 of 9 , Jan 31, 2008
        This is the search.js sheet.

        window.onload = init;

        function init() {
        var ajax = getXMLHttpRequestObject();
        if (ajax) {
        if (document.getElementById('results')){
        document.getElementById('player_search_form').onsubmit = function() {
        var last_name = document.getElementById('last_name').value;
        ajax.open('get', 'player_search_results_xml.php?last_name=' +
        encodeURIComponent(last_name));
        ajax.onreadystatechange = function() {
        handleResponse(ajax);
        }

        ajax.send(null);
        return false;
        }
        }
        }
        }


        function handleResponse(ajax) {
        if (ajax.readyState == 4) {
        if ( (ajax.status == 200) || (ajax.status == 304) ){
        var results = document.getElementById('results');
        results.style.display = 'block';

        while ( results.hasChildNodes() ){
        results.removeChild(results.lastChild);
        }

        var data = ajax.responseXML;

        var names = data.getElementsByTagName('name');
        var teams = data.getElementsByTagName('team');
        var emails = data.getElementsByTagName('email');

        if (names.length > 0) {
        var player, span, name_node, team_node, team_label, br, strong, a, email;

        for (var i=0; i<names.length; i++) {
        player = document.createElement('p');

        span = document.createElement('span');
        span.setAttribute('class', 'name');
        name_node = document.createTextNode(names[i].firstChild.nodeValue);
        span.appendChild(name_node);
        player.appendChild(span);

        br = document.createElement('br');
        player.appendChild(br);

        strong = document.createElement('strong');
        team_label = document.createTextNode('Team');
        strong.appendChild(team_label);
        player.appendChild(strong);
        team_node = document.createTextNode(': '+ teams[i].firstChild.nodeValue);
        player.appendChild(team_node);

        br = document.createElement('br');
        player.appendChild(br);

        a = document.createElement('a');
        a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
        email = document.createTextNode(emails[i].firstChild.nodeValue);
        a.appendChild(email);
        player.appendChild(a);

        results.appendChild(player);

        }
        } else {
        var node1 = document.createElement('p');
        node1.setAttribute('class', 'error');

        var node2 = document.createTextNode('No players were a match.');
        node1.appendChild(node2);

        results.appendChild(node1);
        }
        } else {
        document.getElementById('player_search_form').submit();
        }
        }
        }


        And this is the php page its getting its data from:


        if (!empty($_GET['last_name'])){
        require_once('mysql.inc.php');

        $q = "SELECT CONCAT(last_name, ', ', first_name), email, team_name
        FROM players LEFT JOIN teams USING (team_id) WHERE last_name LIKE
        '".mysql_real_escape_string($_GET['last_name']). "%' ORDER BY
        last_name, first_name";
        $r = mysql_query($q, $dbc);

        if(mysql_num_rows($r) > 0){
        while($row = mysql_fetch_array($r, MYSQL_NUM)) {
        echo "<player>
        <name>$row[0]</name>
        <team>$row[2]</team>
        <email>$row[1]</email>
        </player>\n";
        }
        } else {
        echo '<p class="error">No players were a match</p>';
        }

        mysql_close($dbc);
        }

        echo '</players>';
      • ripple
        Provide code for us to review. wadesmart wrote: Im totally new to JS so I got a book titled Building a Web Site with Ajax and I went
        Message 3 of 9 , Jan 31, 2008
          Provide code for us to review.



          wadesmart <no_reply@yahoogroups.com> wrote:
          Im totally new to JS so I got a book titled Building a Web Site with
          Ajax and I went through the tutorials. I understand them enough in
          their own environment but I moved on and attempted to apply them to my
          own current needs.

          So I really just changed a few names and applied it to my form and it
          seems to work great - until this small problem.

          Really quick, you type in the first few letters of the persons last
          name and hit submit. The script accesses a mysql db through php and
          extracts the data. Its posted back to the page either through php - if
          there is no javascript ability or through ajax if there is.

          When I typed in "S" I have about 30 names that should be pulled up but
          only 4 names are shown. The error console says that this has no
          properties:

          a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);

          Interestingly enough, I installed FireBug and it actually shows me
          that the data returned from the php script HAS all the names in it
          but, what is missing is the email address of a few people. We have
          their first, last names, telephone and email address but not everyone
          provided an email address. So Im assuming when this javascript comes
          up against a blank email it just stops processing.

          My question is, what do you do when you still want the script to put
          out what is there, even if it is empty?

          Wade



          Visit http://aiaiai.com for more groups to join
          Yahoo! Groups Links






          ---------------------------------
          Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

          [Non-text portions of this message have been removed]
        • Alligator
          Without a portion of the problematic code is difficult to figure out what s wrong, but here are few thing to check: 1.- For the look of it you have an email
          Message 4 of 9 , Feb 1, 2008
            Without a portion of the problematic code is difficult to figure out what's wrong, but here are few thing to check:
            1.- For the look of it you have an email array, so I am guessing you also have a names array. Now, do they have the same length??
            2.- If they do, then you should probably check whether each one of these emails[i].firstChild.nodeValue have a valid value; meaning that if you have 20 names and 20 emails then each one of those emails[i].firstChild should NOT be 'undefined'.

            Hope this helps

            Alligator_666
            http://www.vicxsite.com/


            wadesmart <no_reply@yahoogroups.com> wrote: Im totally new to JS so I got a book titled Building a Web Site with
            Ajax and I went through the tutorials. I understand them enough in
            their own environment but I moved on and attempted to apply them to my
            own current needs.

            So I really just changed a few names and applied it to my form and it
            seems to work great - until this small problem.

            Really quick, you type in the first few letters of the persons last
            name and hit submit. The script accesses a mysql db through php and
            extracts the data. Its posted back to the page either through php - if
            there is no javascript ability or through ajax if there is.

            When I typed in "S" I have about 30 names that should be pulled up but
            only 4 names are shown. The error console says that this has no
            properties:

            a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);

            Interestingly enough, I installed FireBug and it actually shows me
            that the data returned from the php script HAS all the names in it
            but, what is missing is the email address of a few people. We have
            their first, last names, telephone and email address but not everyone
            provided an email address. So Im assuming when this javascript comes
            up against a blank email it just stops processing.

            My question is, what do you do when you still want the script to put
            out what is there, even if it is empty?

            Wade






            ---------------------------------
            Never miss a thing. Make Yahoo your homepage.

            [Non-text portions of this message have been removed]
          • Alligator
            I believe the problem is the way you are retrieving the data from the XML. See if you have 20 players but only 10 of them have email address then you ll end up
            Message 5 of 9 , Feb 1, 2008
              I believe the problem is the way you are retrieving the data from the XML. See if you have 20 players but only 10 of them have email address then you'll end up with a names array of 20 elements but an email array of only 10 elements.

              My suggestion is that you retrieve a list of "<player>" instead and check on each one that it has an email branch.

              Alligator_666
              http://www.vicxsite.com



              wadesmart <no_reply@yahoogroups.com> wrote: This is the search.js sheet.

              window.onload = init;

              function init() {
              var ajax = getXMLHttpRequestObject();
              if (ajax) {
              if (document.getElementById('results')){
              document.getElementById('player_search_form').onsubmit = function() {
              var last_name = document.getElementById('last_name').value;
              ajax.open('get', 'player_search_results_xml.php?last_name=' +
              encodeURIComponent(last_name));
              ajax.onreadystatechange = function() {
              handleResponse(ajax);
              }

              ajax.send(null);
              return false;
              }
              }
              }
              }

              function handleResponse(ajax) {
              if (ajax.readyState == 4) {
              if ( (ajax.status == 200) || (ajax.status == 304) ){
              var results = document.getElementById('results');
              results.style.display = 'block';

              while ( results.hasChildNodes() ){
              results.removeChild(results.lastChild);
              }

              var data = ajax.responseXML;

              var names = data.getElementsByTagName('name');
              var teams = data.getElementsByTagName('team');
              var emails = data.getElementsByTagName('email');

              if (names.length > 0) {
              var player, span, name_node, team_node, team_label, br, strong, a, email;

              for (var i=0; i<names.length; i++) {
              player = document.createElement('p');

              span = document.createElement('span');
              span.setAttribute('class', 'name');
              name_node = document.createTextNode(names[i].firstChild.nodeValue);
              span.appendChild(name_node);
              player.appendChild(span);

              br = document.createElement('br');
              player.appendChild(br);

              strong = document.createElement('strong');
              team_label = document.createTextNode('Team');
              strong.appendChild(team_label);
              player.appendChild(strong);
              team_node = document.createTextNode(': '+ teams[i].firstChild.nodeValue);
              player.appendChild(team_node);

              br = document.createElement('br');
              player.appendChild(br);

              a = document.createElement('a');
              a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
              email = document.createTextNode(emails[i].firstChild.nodeValue);
              a.appendChild(email);
              player.appendChild(a);

              results.appendChild(player);

              }
              } else {
              var node1 = document.createElement('p');
              node1.setAttribute('class', 'error');

              var node2 = document.createTextNode('No players were a match.');
              node1.appendChild(node2);

              results.appendChild(node1);
              }
              } else {
              document.getElementById('player_search_form').submit();
              }
              }
              }

              And this is the php page its getting its data from:

              if (!empty($_GET['last_name'])){
              require_once('mysql.inc.php');

              $q = "SELECT CONCAT(last_name, ', ', first_name), email, team_name
              FROM players LEFT JOIN teams USING (team_id) WHERE last_name LIKE
              '".mysql_real_escape_string($_GET['last_name']). "%' ORDER BY
              last_name, first_name";
              $r = mysql_query($q, $dbc);

              if(mysql_num_rows($r) > 0){
              while($row = mysql_fetch_array($r, MYSQL_NUM)) {
              echo "<player>
              <name>$row[0]</name>
              <team>$row[2]</team>
              <email>$row[1]</email>
              </player>\n";
              }
              } else {
              echo '<p class="error">No players were a match</p>';
              }

              mysql_close($dbc);
              }

              echo '</players>';







              ---------------------------------
              Never miss a thing. Make Yahoo your homepage.

              [Non-text portions of this message have been removed]
            • wadesmart
              Some of the players will not have an email - or just wont put it down on the registration form - so there will be some empty emails. Thinking out loud
              Message 6 of 9 , Feb 1, 2008
                Some of the players will not have an email - or just wont put it down
                on the registration form - so there will be some empty emails.

                Thinking out loud here...can I do something like

                if( emails[i] == empty ) {
                exit out of this and move on
                } else {
                a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
                }

                --- In JavaScript_Official@yahoogroups.com, Alligator
                <alligator_666@...> wrote:
                >
                > I believe the problem is the way you are retrieving the data from
                the XML. See if you have 20 players but only 10 of them have email
                address then you'll end up with a names array of 20 elements but an
                email array of only 10 elements.
                >
                > My suggestion is that you retrieve a list of "<player>" instead and
                check on each one that it has an email branch.
                >
                > Alligator_666
                > http://www.vicxsite.com
                >
                >
                >
                > wadesmart <no_reply@yahoogroups.com> wrote:
                This is the search.js sheet.
                >
                > window.onload = init;
                >
                > function init() {
                > var ajax = getXMLHttpRequestObject();
                > if (ajax) {
                > if (document.getElementById('results')){
                > document.getElementById('player_search_form').onsubmit = function() {
                > var last_name = document.getElementById('last_name').value;
                > ajax.open('get', 'player_search_results_xml.php?last_name=' +
                > encodeURIComponent(last_name));
                > ajax.onreadystatechange = function() {
                > handleResponse(ajax);
                > }
                >
                > ajax.send(null);
                > return false;
                > }
                > }
                > }
                > }
                >
                > function handleResponse(ajax) {
                > if (ajax.readyState == 4) {
                > if ( (ajax.status == 200) || (ajax.status == 304) ){
                > var results = document.getElementById('results');
                > results.style.display = 'block';
                >
                > while ( results.hasChildNodes() ){
                > results.removeChild(results.lastChild);
                > }
                >
                > var data = ajax.responseXML;
                >
                > var names = data.getElementsByTagName('name');
                > var teams = data.getElementsByTagName('team');
                > var emails = data.getElementsByTagName('email');
                >
                > if (names.length > 0) {
                > var player, span, name_node, team_node, team_label, br, strong, a,
                email;
                >
                > for (var i=0; i<names.length; i++) {
                > player = document.createElement('p');
                >
                > span = document.createElement('span');
                > span.setAttribute('class', 'name');
                > name_node = document.createTextNode(names[i].firstChild.nodeValue);
                > span.appendChild(name_node);
                > player.appendChild(span);
                >
                > br = document.createElement('br');
                > player.appendChild(br);
                >
                > strong = document.createElement('strong');
                > team_label = document.createTextNode('Team');
                > strong.appendChild(team_label);
                > player.appendChild(strong);
                > team_node = document.createTextNode(': '+
                teams[i].firstChild.nodeValue);
                > player.appendChild(team_node);
                >
                > br = document.createElement('br');
                > player.appendChild(br);
                >
                > a = document.createElement('a');
                > a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
                > email = document.createTextNode(emails[i].firstChild.nodeValue);
                > a.appendChild(email);
                > player.appendChild(a);
                >
                > results.appendChild(player);
                >
                > }
                > } else {
                > var node1 = document.createElement('p');
                > node1.setAttribute('class', 'error');
                >
                > var node2 = document.createTextNode('No players were a match.');
                > node1.appendChild(node2);
                >
                > results.appendChild(node1);
                > }
                > } else {
                > document.getElementById('player_search_form').submit();
                > }
                > }
                > }
                >
                > And this is the php page its getting its data from:
                >
                > if (!empty($_GET['last_name'])){
                > require_once('mysql.inc.php');
                >
                > $q = "SELECT CONCAT(last_name, ', ', first_name), email, team_name
                > FROM players LEFT JOIN teams USING (team_id) WHERE last_name LIKE
                > '".mysql_real_escape_string($_GET['last_name']). "%' ORDER BY
                > last_name, first_name";
                > $r = mysql_query($q, $dbc);
                >
                > if(mysql_num_rows($r) > 0){
                > while($row = mysql_fetch_array($r, MYSQL_NUM)) {
                > echo "<player>
                > <name>$row[0]</name>
                > <team>$row[2]</team>
                > <email>$row[1]</email>
                > </player>\n";
                > }
                > } else {
                > echo '<p class="error">No players were a match</p>';
                > }
                >
                > mysql_close($dbc);
                > }
                >
                > echo '</players>';
                >
                >
                >
                >
                >
                >
                >
                > ---------------------------------
                > Never miss a thing. Make Yahoo your homepage.
                >
                > [Non-text portions of this message have been removed]
                >
              • David Smart
                There s a lot of code quoted there, and some of the subroutines are quite long. (I assume they are indented properly in your code, but this has been stripped
                Message 7 of 9 , Feb 1, 2008
                  There's a lot of code quoted there, and some of the subroutines are quite
                  long. (I assume they are indented properly in your code, but this has been
                  stripped out by the e-mail, making it very difficult to read quickly.) You
                  might like to consider restructuring it a bit so that individual routines
                  are shorter and easier to read.

                  Going back to your previous message, you had said that the error console was
                  reporting that

                  a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);

                  had no properties.

                  This presumably means that emails[i].firstChild.nodeValue has no properties.
                  You're also saying that there are some missing e-mails. So it sounds as
                  though a missing e-mail causes a null value or different structure to be put
                  in the respective emails[i]. Looks as though you need to check for null
                  items in the array before you start grabbing their properties. Or it could
                  be that its firstChild is null if it's empty.

                  You probably need to put some test code in before the statement concerned
                  and alert() out the emails[i] items and their properties before you try to
                  use them.

                  Seeing that you use the same construct a couple of times, you might like to
                  write a function that takes emails[i] as a parameter and returns the value
                  of the first child node, if there is one, or an empty string, if there
                  isn't. Such a function could be useful for items in other node arrays too.
                  (The construct ".firstChild.nodeValue" is used in four places in your code -
                  calls to a common function could replace all these and then deal robustly
                  with other missing values too.)

                  Regards, Dave S

                  ----- Original Message -----
                  From: "wadesmart" <no_reply@yahoogroups.com>
                  To: <JavaScript_Official@yahoogroups.com>
                  Sent: Friday, February 01, 2008 2:27 PM
                  Subject: Re: [JavaScript] script stops when an array element is empty


                  > This is the search.js sheet.
                  >
                  > window.onload = init;
                  >
                  > function init() {
                  > var ajax = getXMLHttpRequestObject();
                  > if (ajax) {
                  > if (document.getElementById('results')){
                  > document.getElementById('player_search_form').onsubmit = function() {
                  > var last_name = document.getElementById('last_name').value;
                  > ajax.open('get', 'player_search_results_xml.php?last_name=' +
                  > encodeURIComponent(last_name));
                  > ajax.onreadystatechange = function() {
                  > handleResponse(ajax);
                  > }
                  >
                  > ajax.send(null);
                  > return false;
                  > }
                  > }
                  > }
                  > }
                  >
                  >
                  > function handleResponse(ajax) {
                  > if (ajax.readyState == 4) {
                  > if ( (ajax.status == 200) || (ajax.status == 304) ){
                  > var results = document.getElementById('results');
                  > results.style.display = 'block';
                  >
                  > while ( results.hasChildNodes() ){
                  > results.removeChild(results.lastChild);
                  > }
                  >
                  > var data = ajax.responseXML;
                  >
                  > var names = data.getElementsByTagName('name');
                  > var teams = data.getElementsByTagName('team');
                  > var emails = data.getElementsByTagName('email');
                  >
                  > if (names.length > 0) {
                  > var player, span, name_node, team_node, team_label, br, strong, a, email;
                  >
                  > for (var i=0; i<names.length; i++) {
                  > player = document.createElement('p');
                  >
                  > span = document.createElement('span');
                  > span.setAttribute('class', 'name');
                  > name_node = document.createTextNode(names[i].firstChild.nodeValue);
                  > span.appendChild(name_node);
                  > player.appendChild(span);
                  >
                  > br = document.createElement('br');
                  > player.appendChild(br);
                  >
                  > strong = document.createElement('strong');
                  > team_label = document.createTextNode('Team');
                  > strong.appendChild(team_label);
                  > player.appendChild(strong);
                  > team_node = document.createTextNode(': '+ teams[i].firstChild.nodeValue);
                  > player.appendChild(team_node);
                  >
                  > br = document.createElement('br');
                  > player.appendChild(br);
                  >
                  > a = document.createElement('a');
                  > a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
                  > email = document.createTextNode(emails[i].firstChild.nodeValue);
                  > a.appendChild(email);
                  > player.appendChild(a);
                  >
                  > results.appendChild(player);
                  >
                  > }
                  > } else {
                  > var node1 = document.createElement('p');
                  > node1.setAttribute('class', 'error');
                  >
                  > var node2 = document.createTextNode('No players were a match.');
                  > node1.appendChild(node2);
                  >
                  > results.appendChild(node1);
                  > }
                  > } else {
                  > document.getElementById('player_search_form').submit();
                  > }
                  > }
                  > }
                  >
                  >
                  > And this is the php page its getting its data from:
                  >
                  >
                  > if (!empty($_GET['last_name'])){
                  > require_once('mysql.inc.php');
                  >
                  > $q = "SELECT CONCAT(last_name, ', ', first_name), email, team_name
                  > FROM players LEFT JOIN teams USING (team_id) WHERE last_name LIKE
                  > '".mysql_real_escape_string($_GET['last_name']). "%' ORDER BY
                  > last_name, first_name";
                  > $r = mysql_query($q, $dbc);
                  >
                  > if(mysql_num_rows($r) > 0){
                  > while($row = mysql_fetch_array($r, MYSQL_NUM)) {
                  > echo "<player>
                  > <name>$row[0]</name>
                  > <team>$row[2]</team>
                  > <email>$row[1]</email>
                  > </player>\n";
                  > }
                  > } else {
                  > echo '<p class="error">No players were a match</p>';
                  > }
                  >
                  > mysql_close($dbc);
                  > }
                  >
                  > echo '</players>';
                  >
                  >
                  >
                  >
                  > Visit http://aiaiai.com for more groups to join
                  > Yahoo! Groups Links
                  >
                  >
                  >
                • David Smart
                  I m not aware of any JavaScript test for empty , but there is a test against null. As I think I mentioned in my previous e-mail, I don t know whether you d
                  Message 8 of 9 , Feb 4, 2008
                    I'm not aware of any JavaScript test for "empty", but there is a test
                    against null.

                    As I think I mentioned in my previous e-mail, I don't know whether you'd
                    check against emails[i] or against emails[i].firstChild, or even if that is
                    the problem. You'll need to see what's in there first.

                    Regards, Dave S

                    ----- Original Message -----
                    From: "wadesmart" <no_reply@yahoogroups.com>
                    To: <JavaScript_Official@yahoogroups.com>
                    Sent: Saturday, February 02, 2008 7:32 AM
                    Subject: Re: [JavaScript] script stops when an array element is empty


                    > Some of the players will not have an email - or just wont put it down
                    > on the registration form - so there will be some empty emails.
                    >
                    > Thinking out loud here...can I do something like
                    >
                    > if( emails[i] == empty ) {
                    > exit out of this and move on
                    > } else {
                    > a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
                    > }
                    >
                    > --- In JavaScript_Official@yahoogroups.com, Alligator
                    > <alligator_666@...> wrote:
                    >>
                    >> I believe the problem is the way you are retrieving the data from
                    > the XML. See if you have 20 players but only 10 of them have email
                    > address then you'll end up with a names array of 20 elements but an
                    > email array of only 10 elements.
                    >>
                    >> My suggestion is that you retrieve a list of "<player>" instead and
                    > check on each one that it has an email branch.
                    >>
                    >> Alligator_666
                    >> http://www.vicxsite.com
                    >>
                    >>
                    >>
                    >> wadesmart <no_reply@yahoogroups.com> wrote:
                    > This is the search.js sheet.
                    >>
                    >> window.onload = init;
                    >>
                    >> function init() {
                    >> var ajax = getXMLHttpRequestObject();
                    >> if (ajax) {
                    >> if (document.getElementById('results')){
                    >> document.getElementById('player_search_form').onsubmit = function() {
                    >> var last_name = document.getElementById('last_name').value;
                    >> ajax.open('get', 'player_search_results_xml.php?last_name=' +
                    >> encodeURIComponent(last_name));
                    >> ajax.onreadystatechange = function() {
                    >> handleResponse(ajax);
                    >> }
                    >>
                    >> ajax.send(null);
                    >> return false;
                    >> }
                    >> }
                    >> }
                    >> }
                    >>
                    >> function handleResponse(ajax) {
                    >> if (ajax.readyState == 4) {
                    >> if ( (ajax.status == 200) || (ajax.status == 304) ){
                    >> var results = document.getElementById('results');
                    >> results.style.display = 'block';
                    >>
                    >> while ( results.hasChildNodes() ){
                    >> results.removeChild(results.lastChild);
                    >> }
                    >>
                    >> var data = ajax.responseXML;
                    >>
                    >> var names = data.getElementsByTagName('name');
                    >> var teams = data.getElementsByTagName('team');
                    >> var emails = data.getElementsByTagName('email');
                    >>
                    >> if (names.length > 0) {
                    >> var player, span, name_node, team_node, team_label, br, strong, a,
                    > email;
                    >>
                    >> for (var i=0; i<names.length; i++) {
                    >> player = document.createElement('p');
                    >>
                    >> span = document.createElement('span');
                    >> span.setAttribute('class', 'name');
                    >> name_node = document.createTextNode(names[i].firstChild.nodeValue);
                    >> span.appendChild(name_node);
                    >> player.appendChild(span);
                    >>
                    >> br = document.createElement('br');
                    >> player.appendChild(br);
                    >>
                    >> strong = document.createElement('strong');
                    >> team_label = document.createTextNode('Team');
                    >> strong.appendChild(team_label);
                    >> player.appendChild(strong);
                    >> team_node = document.createTextNode(': '+
                    > teams[i].firstChild.nodeValue);
                    >> player.appendChild(team_node);
                    >>
                    >> br = document.createElement('br');
                    >> player.appendChild(br);
                    >>
                    >> a = document.createElement('a');
                    >> a.setAttribute('href', 'mailto:' + emails[i].firstChild.nodeValue);
                    >> email = document.createTextNode(emails[i].firstChild.nodeValue);
                    >> a.appendChild(email);
                    >> player.appendChild(a);
                    >>
                    >> results.appendChild(player);
                    >>
                    >> }
                    >> } else {
                    >> var node1 = document.createElement('p');
                    >> node1.setAttribute('class', 'error');
                    >>
                    >> var node2 = document.createTextNode('No players were a match.');
                    >> node1.appendChild(node2);
                    >>
                    >> results.appendChild(node1);
                    >> }
                    >> } else {
                    >> document.getElementById('player_search_form').submit();
                    >> }
                    >> }
                    >> }
                    >>
                    >> And this is the php page its getting its data from:
                    >>
                    >> if (!empty($_GET['last_name'])){
                    >> require_once('mysql.inc.php');
                    >>
                    >> $q = "SELECT CONCAT(last_name, ', ', first_name), email, team_name
                    >> FROM players LEFT JOIN teams USING (team_id) WHERE last_name LIKE
                    >> '".mysql_real_escape_string($_GET['last_name']). "%' ORDER BY
                    >> last_name, first_name";
                    >> $r = mysql_query($q, $dbc);
                    >>
                    >> if(mysql_num_rows($r) > 0){
                    >> while($row = mysql_fetch_array($r, MYSQL_NUM)) {
                    >> echo "<player>
                    >> <name>$row[0]</name>
                    >> <team>$row[2]</team>
                    >> <email>$row[1]</email>
                    >> </player>\n";
                    >> }
                    >> } else {
                    >> echo '<p class="error">No players were a match</p>';
                    >> }
                    >>
                    >> mysql_close($dbc);
                    >> }
                    >>
                    >> echo '</players>';
                    >>
                    >>
                    >>
                    >>
                    >>
                    >>
                    >>
                    >> ---------------------------------
                    >> Never miss a thing. Make Yahoo your homepage.
                    >>
                    >> [Non-text portions of this message have been removed]
                    >>
                    >
                    >
                    >
                    >
                    > Visit http://aiaiai.com for more groups to join
                    > Yahoo! Groups Links
                    >
                    >
                    >
                  Your message has been successfully submitted and would be delivered to recipients shortly.