Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search data island

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
I have code to navigate records held within an xml data island (data.xml)


function first(){
data.recordset.moveFirst();
}
function previous(){
if(data.recordset.absoluteposition>1)
data.recordset.movePrevious();
}
function next(){
if(data.recordset.absoluteposition <
data.recordset.recordcount)
data.recordset.moveNext();
}
function last(){
data.recordset.moveLast();
}


which works nicely.

However, what i need to do, is (when the user types in letters into an <input>) search the data island for nodes in which the name field starts with the letters typed in...
eg if user types &quot;ice&quot; I need to retrieve the &quot;icehouse&quot; node and the &quot;icecream&quot; nodes/records.

Can anyone here help me? I am not a Javascript programmer (and just learning about xml to boot), what i would like is something along the lines of

data.recordset.find(fieldname, 'string');


Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Take a look at this code, look especially at function doselect and button &quot;select a page number&quot;
Code:
<html>
<head>
  <!-- Template of XML Data Island, Author Ion Filipski -->
  <title>dynamic HTML with XML Data Island</title>
  <xml id=&quot;xmlmeetings&quot;>
    <?xml version=&quot;1.0&quot;?>
      <meetings>
        <meeting>
          <date>1/1/99</date><time>9:00</time><location>Munhen</location>
        </meeting>
        <meeting>
          <date>2/1/99</date><time>13:00</time><location>Bucharest</location>
        </meeting>
        <meeting>
          <date>3/1/99</date><time>14:30</time><location>NewYork</location>
        </meeting>
        <meeting>
          <date>3/1/99</date><time>14:30</time><location>Paris</location>
        </meeting>
        <meeting>
          <date>3/1/99</date><time>14:30</time><location>Beijing</location>
        </meeting>
      </meetings>
  </xml>
  <script language=&quot;JScript&quot;>
    var meetings;
    var meeting;
    var name;
    var i;
    var j;
    var currentPage = 0;
    var doc = document;
    meetings = xmlmeetings.documentElement.selectNodes(&quot;meeting&quot;);
    var x = 0;

    function doWriteHead()
    {
      meeting = meetings[x];
      var strHtml = &quot;&quot;;
      strHtml = &quot;meeting {&quot; + (x + 1) + &quot;}:<br/>&quot;;
      strHtml = strHtml + &quot;<table border=\&quot;1\&quot;>&quot;;
      for(i = 0; i < meeting.childNodes.length; i++)
      {
        strHtml = strHtml + &quot;\n<tr><td>&quot;;
        strHtml = strHtml + meeting.childNodes[i].nodeName;
        strHtml = strHtml + &quot;</td><td>&quot;;
        strHtml = strHtml + meeting.childNodes[i].text;
        strHtml = strHtml + &quot;</td></tr>&quot;;
      }
      doc.all.detail.innerHTML = strHtml;
    }
    function doNext()
    {
      if(x < (meetings.length - 1))x++;
      doWriteHead();
    }
    function doPrev()
    {
      if(x > 0)x--;
      doWriteHead();
    }
    function doSelect()
    {
      x = doc.all.pagenum.value;
      doc.all.pagenum.value = &quot;&quot;;
      doPrev();
    }
  </script>
</head>
<body id>
  press next or prev page to view meetings:<br/>
  <input type=&quot;button&quot; value=&quot;prev page&quot; onclick=&quot;javascript:doPrev();&quot;/>
  <input type=&quot;button&quot; value=&quot;next page&quot; onclick=&quot;javascript:doNext();&quot;/><br/>
  <input type=&quot;button&quot; value=&quot;select a page number&quot; onclick=&quot;javascript:doSelect();&quot;/>
  <input type=&quot;text&quot; id=&quot;pagenum&quot;/><br/>
  <p id = &quot;detail&quot;/>
</body>
</html>

Ion Filipski
1c.bmp
 
so how then would you find the page if you asked the user to type in the first 3 letters of the meeeting.location instead of the page number?


Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
no, place a number or meeting. There are five meetings, so choose from 1 to 5

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top