Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

Arrays, Object Arrays and Sorting

Seek, and ye shall find

Text Strings and String Objects

Searching- source3

You are here: irt.org | Articles | JavaScript | Object | Searching [ previous next ]

Published on: Sunday 9th February 1997 By: Martin Webb

results.htm source code

<html lang="en">
<head>

<title>Search Results</title>

</head>

<body>

<script language="JavaScript"><!--
var old = 0;
var pos = 0;
var lst = 0;
var str = '';
var out = '';
var src = parent.searchtext.toUpperCase();
var len = parent.searchtext.length;

function find() {
  var string = 
    out.substring(old+len,pos) +
    '<i><font color="#0000FF" size=+"1">' +
    out.substring(pos,pos+len) +
    '</font></i>';
  old = pos;
  pos = str.indexOf(src,pos+len);
  if ((pos != -1) && (old != lst)) string += find();
  else string += out.substring(old+len,out.length);
  return string;
}

function show(tmp) {
  if (src != '') {
    out = tmp + ' ';
    str = out.toUpperCase();
    pos = str.indexOf(src);
    lst = str.lastIndexOf(src);
    old = -(str.length);
    if (pos != -1) return find();
    else return out;
  }
  else return tmp;
}

function output() {
  var href = parent.articleArray[i].href;
  var desc = parent.articleArray[i].desc;
  var text = parent.articleArray[i].text;
  var tech = parent.articleArray[i].tech;
  var date = convert_date(parent.articleArray[i].date);

  document.write('<tr><td valign="top">');
  document.write('<font face="Verdana, Arial, Helvetica">');
  document.write('<font size="4">');
  document.write('<a href="' + href + '" target="_parent">');
  document.write(show(text));
  document.write('</a></font>');
  if (parent.vdate) {
    document.write('<font size="2"><br>');
    document.write(show(date)+'</font>');
  }
  document.write('</font></td>');
  document.write('<td valign="top">');
  document.write('<font face="Arial" size="3">');
  if (parent.vhref) {
    document.write('<font size="2">');
    document.write('<a href="' + href + '" target="_parent">');
    document.write(show(href) + '</a></font>');
  }
  if (parent.vdesc)
    document.write('<p>'+show(desc));
  if (parent.vtech) {
    document.write('<p><b>Techniques:</b> ');
    document.write(show(tech));
  }
  document.write('</font></td></tr>');
}

function makeArray() {
  for (i = 0; i<makeArray.arguments.length; i++)
     this[i + 1] = makeArray.arguments[i];
}

function makeArray0() {
  for (i = 0; i<makeArray0.arguments.length; i++)
    this[i] = makeArray0.arguments[i];
}

var days = new makeArray0(
  'Sunday','Monday','Tuesday','Wednesday',
  'Thursday','Friday','Saturday'
);
var months = new makeArray0(
  'January','February','March','April',
  'May','June','July','August','September',
  'October','November','December'
);

function nths(day) { 
  if (day == 1 || day == 21 || day == 31)
    return 'st';
  else
    if (day == 2 || day == 22)
      return 'nd';
    if (day == 3 || day == 23)
      return 'rd';
    else return 'th';
}

function y2k(number) {
  return (number < 1000) ? number + 1900 : number;
}

function fullDate(date) {
  return days[date.getDay()] + ' ' +
         date.getDate() + nths(date.getDate()) + ' ' +
         months[date.getMonth()] + ' ' +
         (y2k(date.getYear()));
}

function convert_date(string) {
  var date =
    new Date(
      string.substring(0,4),
      (string.substring(4,6)-1),
      string.substring(6,8)
    );
  return fullDate(date);
}

if (parent.searchtext != '') {
  document.write('<h1>Search Results</h1>');
  document.write('<h2>Search string = \'' + parent.searchtext + '\'</h2>');
}
else {
  document.write('<h1>JavaScript</h1>');
  document.write('<h2>The following JavaScript demonstrations are available:</h2>');
}

document.write('<table cellpadding="10">');
var is = parent.searchtext.toUpperCase();

for (var i=0; i < parent.articleIndex; i++) {
  if ((parent.articleArray[i].href.toUpperCase().indexOf(is) != -1) ||
    (parent.articleArray[i].desc.toUpperCase().indexOf(is) != -1) ||
    (parent.articleArray[i].tech.toUpperCase().indexOf(is) != -1) ||
    (parent.articleArray[i].date.toUpperCase().indexOf(is) != -1))
      output();
}


document.write('</table>');
//--></script>

</body>
</html>

Related items

Arrays, Object Arrays and Sorting

Seek, and ye shall find

Text Strings and String Objects

©2018 Martin Webb