...

View Full Version : As output this



lebronletchev
07-10-2007, 09:33 AM
Hi

Please I need your help for doing a function (in advance) named "OutputMe" bear in mind the same structure below.




<div id="hidnMyText" style="display: none;">If a record-breaking heat wave doesn't lift soon, cattle rancher Sharon McDonald may see her hay crop turn to dust. Oppressive temperatures eased a bit Friday in some parts of the West, but McDonald's central Montana ranch baked under triple-digit heat.</div>
<div id="mytext"><a href="#" onclick="OutputMe('if');">if </a>&nbsp;<a href="#" onclick="OutputMe('a');">a</a>&nbsp;<a href="#" onclick="OutputMe('record-breaking');">record-breaking</a>&nbsp;<a href="#" onclick="conc('heat');">heat</a>&nbsp;<a href="#" onclick="OutputMe('wave');">wave</a>&nbsp;<a href="#" onclick="OutputMe('doens´t');">doesn't<a/>&nbsp;<a href="#" onclick="OutputMe('lift');">lift<a/>&nbsp;<a href="#" onclick="OutputMe('soon');">soon</a>&nbsp;<a href="#" onclick="OutputMe('cattle');">cattle</a>&nbsp;<a href="#" onclick="OutputMe('rancher');">rancher</a>&nbsp;<a href="#" onclick="OutputMe('McDonald');">McDonald</a>&nbsp;<a href="#" onclick="OutputMe('central');">central</a>&nbsp;
<a href="#" onclick="OutputMe('Montana');">Montana<a/>&nbsp;<a href="#" onclick="OutputMe('ranch');">ranch<a/>&nbsp;<a href="#" onclick="OutputMe('baked');">baked<a/>&nbsp;<a href="#" onclick="OutputMe('under');">under<a/>&nbsp;<a href="#" onclick="OutputMe('triple-digit');">triple-digit<a/>&nbsp;<a href="#" onclick="OutputMe('heat');">heat<a/>&nbsp;</div>
<div id="results"></div>


I want output the clicked keyword + its neighbourings.

For example:

Click on "soon" and will see
<a href="#" onclick="OutputMe('lift');">lift<a/>&nbsp;<a href="#" onclick="OutputMe('soon');">soon</a>&nbsp;<a href="#" onclick="OutputMe('cattle');">cattle</a>

If there is not at left or at right of the "keyword" it gives nothing.

Thank you

Lebron

Kor
07-10-2007, 12:11 PM
like this?:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function OutputMe(obj){
var txt=''
var thisT=obj.firstChild.data;
var prevT=findSibling(obj.previousSibling,true);
var nextT=findSibling(obj.nextSibling,false);
prevT.length>0?prevT+=' ':null;
nextT.length>0?nextT=' '+nextT:null;
txt=prevT+thisT+nextT;
document.getElementById('results').firstChild.data=txt;
}
function findSibling(s,b){
var txt=''
while(s.nodeType!=1){
s=b?s.previousSibling:s.nextSibling;
if(s&&s.nodeType==1){
txt=s.firstChild.data;
return txt
}
else{
return txt
}
}
}
onload=function(){
var allA=document.getElementById('mytext').getElementsByTagName('a'), i=0, a;
while(a=allA[i++]){
a.onclick=function(){OutputMe(this);return false}
}
}
</script>
</head>
<body>
<div id="mytext">
<a href="#">if</a>&nbsp;
<a href="#">a</a>&nbsp;
<a href="#">record-breaking</a>&nbsp;
<a href="#">heat</a>&nbsp;
<a href="#">wave</a>&nbsp;
<a href="#">doesn't</a>&nbsp;
<a href="#">lift</a>&nbsp;
<a href="#">soon</a>&nbsp;
<a href="#">cattle</a>&nbsp;
<a href="#">rancher</a>&nbsp;
<a href="#">McDonald</a>&nbsp;
<a href="#">central</a>&nbsp;
<a href="#">Montana</a>&nbsp;
<a href="#">ranch</a>&nbsp;
<a href="#">baked</a>&nbsp;
<a href="#">under</a>&nbsp;
<a href="#">triple-digit</a>&nbsp;
<a href="#">heat</a>&nbsp;
</div>
<div id="results">&nbsp;</div>
</body>
</html>


Off the topic: take care how you close the tags. Should be </a> not <a/>

lebronletchev
07-10-2007, 04:02 PM
Yes. Thank you.

lebronletchev
07-10-2007, 04:09 PM
I tested your script with an .ASP output:

In your script - which works very fine - it is possible read one line only. What I must change in your script for reading several lines?

For example

<div align=center id="mytext">
<a href="#"><%response.write rs("texts")%></a>&nbsp;
</div>

Thanks

Lebron

Kor
07-10-2007, 09:19 PM
I don't know ASP, just basic PHP ... Do you have problems with the code?

glenngv
07-10-2007, 09:31 PM
You mean this?

<%
while not rs.BOF and not rs.EOF
%>
<a href="#"><%=rs("texts")%></a>&nbsp;
<%
rs.movenext
wend
%>

lebronletchev
07-12-2007, 08:18 PM
Glenngy,

Yes, you are right, but there are details difficult to explain.

Thanks

Lebron



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum