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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to use Javascript to do a search

Status
Not open for further replies.

jbemp

Programmer
Dec 10, 2004
2
US
I have a site that does not have a database back end. It is just a list of terms with descriptions. Is there some way that I could have a search field that would go to the correct term without creating a database?
Thanx
John
 
If you had the terms and descriptions in a JS array, you could search that. You could either create the array of objects with the term as one property and the description as another, or use an associative array where the array element was the term, such as:

var term=new Array();
term['dictionary']='Book of definitions';
term['car seat']='Where you sit when you travel in a car';

then you could just access the term by the term word, like:

function getTerm(termword)
{
return term[termword];
}

var oneterm=getTerm('dictionary');
//would equal "Book of definitions"

Lee
 
I couldn't find it so just wrote something up quickly. I added a lot of empty paragraphs as padding just so you could see the effect:

Code:
<html>
<head>
<title>PostScript Operators</title>
<script type="text/javascript">
function doSearch()
{
  window.location.hash = document.getElementById("searchTerm").value;
}
</script>
</head>
<body>

<div>
<p>
<a name="add">add</a>
<br/>
<br/>
Usage: num1 num2 add sum<br/><br/>
returns the sum of num1 and num2. If both operands are integers and the result is
within integer range, the result is an integer; otherwise, the result is a real number.<br/>
Examples<br/>
3 4 add Þ 7<br/>
9.9 1.1 add Þ 11.0<br/><br/>
Errors: stackunderflow, typecheck, undefinedresult<br/>
See Also: div, mul, sub, idiv, mod<br/>
</p>
<hr/>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<p>
<a name="div">div</a>
<br/>
<br/>
Usage: num1 num2 div quotient<br/><br/>
divides num1 by num2, producing a result that is always a real number even if both
operands are integers. Use idiv instead if the operands are integers and an integer
result is desired.<br/>
Examples<br/>
3 2 div Þ 1.5<br/>
4 2 div Þ 2.0<br/><br/>
Errors: stackunderflow, typecheck, undefinedresult<br/>
See Also: idiv, add, mul, sub, mod<br/>
</p>
<hr/>
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<div>
<form>
<label for="searchTerm">Find a term: </label>
<input type="text" id="searchTerm" />
<input type="button" value="Search" onclick="doSearch()" />
</form>
</div>

</body>
</html>


If you found this post helpful, I invite you to visit my site and support it by clicking some adds. Tek-Tips is also advertiser supported. Click Ads!



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Thanx tgreer,
That was what I was thinking but was a little unsure of the exact coding. I was close.
Thanx
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top