Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: As output this

  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool As output this

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    like this?:
    Code:
    <!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/>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes. Thank you.

  • #4
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I don't know ASP, just basic PHP ... Do you have problems with the code?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You mean this?
    Code:
    <%
    while not rs.BOF and not rs.EOF
    %>
      <a href="#"><%=rs("texts")%></a>&nbsp;
    <%
       rs.movenext
    wend
    %>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Glenngy,

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

    Thanks

    Lebron


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •