PDA

View Full Version : Search trouble



c1hundred
05-16-2009, 01:54 PM
hi, what i want to do is this:

type something into a text field, if a div with a rel that is the same as the text field value show that div.


<script type="text/javascript">
function search() {
var search = document.getElementById('search').value;
var results = document.getAttribute('rel');
var resultsIf = results = search;
if (resultsIf = true){
results.style.display = "block";
}
</script>
</head>
<body>
<div rel="go" style="border:0;display:none;">hello there!</div>
<input type="text" id="search"><input type="button" onclick="search()">

cheers

Nile
05-17-2009, 01:49 PM
Div in the document? So basically you type: box, and all divs with the rel="box" attribute and value display?



<script type="text/javascript">
var searchRel = function(el){
for(i=0;(a=document.getElementsByTagName('div'));i++){
[i]if(el.value == a.getAttribute("rel")){ a.style.display = "block"; }
if(el.value != a.getAttribute("rel")){ a.style.display = "none"; }
}
};
</script>
<input type="text" name="search" onkeyup="searchRel(this);" />
<div rel="lightblue" style="display:none;width:100px;height:200px;background:lightblue;">Hello</div><div rel="brown" style="display:none;width:500px;height:220px;background:brown;">How are you?</div><div rel="green" style="display:none;width:300px;height:620px;background:green;">Green!</div>

You can try typing lightblue, brown, and green.