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

    Cool As change <textarea> to <div> ?

    Hi,

    I am trying to have the same results using a <div></div>, no success.

    Could you please give me a bit of help?

    My script:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form name="myform" method="post" action="lixo.asp">
    <p>
    <textarea name="mytext" rows=20 cols=80>
    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.
    Forecasters reported little relief in the days ahead, saying the weather system that brought the
    high temperatures could last well into next week.
    </textarea>
    </p>
    <p>
    <input type="text" name="key" value="" />
    <input name="submit" type="submit" />
    </p>
    </form>
    <%if request.Form("submit")<>"" then
    dim str
    str = " " & request.Form("myText") & " "
    ary=split(str," ",1)
    for i=0 to Ubound(ary)
    if ary(i)=Request.Form("key") then%>

    <%Response.write ary %>

    <%
    end if
    next
    end if%>
    </body>
    </html>
    The goal of script is output a list of words written on a <div></div>.

    Thank you

    Lebron

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

    444 views and reply = nothing!

    At least do you can the following: copy and paste and add to your favorites scripts! it is a good way and politics.

    Lebron

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    I am not sure what you are trying to accomplish, because the code above doesn't work.

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <%
    if request.form("submit")<>"" then
    dim str
    str = " " & request.Form("mytext") & " "
    ary=split(str," ")
    for i=0 to Ubound(ary)
    	if ary(i)=Request.Form("key") then response.write("<div>" & ary(i) & "</div>")
    next
    end if%>
    
    <form name="myform" method="post" action="lixo.asp">
    <p>
    <textarea name="mytext" rows=20 cols=80>
    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. Forecasters reported little relief in the days ahead, saying the weather system that brought the high temperatures could last well into next week.
    </textarea>
    </p>
    <p>
    <input type="text" name="key" value="" />
    <input name="submit" type="submit" />
    </p>
    </form>
    </body>
    </html>
    That code does...

    Now, if you are trying to find the location of the requested text IN the array, then you need to use:

    Code:
    for i=0 to Ubound(ary)
    	if ary(i)=Request.Form("key") then response.write("<div>" & i & "</div>")
    next
    I searched for "that" and received 54 as the answer ("that" is the 54th word in the array).

    You want the <textarea> to become a <div>? Then use Javascript, not ASP.

    I am working on this for you now, and should have something for you after my coffee...

    HTH!
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    As I promised (now that my coffee has kicked in... )

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <script language="javascript">
    function findMe() {
    	document.getElementById('results').innerHTML = "";
    	var theField = ' ' + document.getElementById('mytext').innerHTML + ' ';
    	var theString = document.myform.key.value;
    	
    	var items = theField.split(" ");
    	
    	for(var i=0;i<items.length;i++) {
    		if(items[i] == theString) {
    			document.getElementById('results').innerHTML += '<div>' + i + '</div>';
    		}
    	}
    }
    </script>
    <div id="mytext">
    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. 
    Forecasters reported little relief in the days ahead, saying the weather system that brought 
    the high temperatures could last well into next week.
    </div>
    <form name="myform" action="lixo.asp">
    <p><input type="text" name="key" value="" /> <input value="Submit Query" type="button" onclick="findMe();" /></p>
    </form>
    <div id="results"></div>
    </body>
    </html>
    Last edited by Daemonspyre; 07-09-2007 at 02:23 PM. Reason: Added a "clear old results" line
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Daemonspyre

    Thank you for your collaboration, in many things you are right. In short I want two things:

    1. Eliminate "submit button"
    2. Output in <div>HYPERTEXTS</div>
    3. When the user "click on" a hyperlinks, it will see in headline the line where is found that word in a separate page.

    I am trying use your script todo I said above, but no success.

    Thank you again

    Lebron

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Ah...

    Try this (and let me know if this is what you are looking for), but there are a couple of notes:

    1) Because of the HREFs, I had to add a second <div> tag with your data in it. The addition of the HTML code messed with the array positioning and messed up the javascript in general (quotes, <, >, and / have a tendency to do that). You may want to jump over to the JavaScript forum to see if they can make this code better for your needs.

    2) You have to add HREFs for every word that you want to search for. Can be a little time consuming, but if you make it database driven, then you need to do a little heavy lifting at first to get this to work for you, but then it will be smooth sailing later on.

    3) You said above that you want to know what LINE the text is found in. This code doesn't do that. It tells you what position in the array the word is found. If you want to know what line it's in, this whole discussion becomes moot because it's not what you originally wanted. The code becomes altogether something different.

    HTH!

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <script language="javascript">
    function findMe(str) {
    	document.getElementById('results').innerHTML = "";
    	var theField = ' ' + document.getElementById('hidnMyText').innerHTML + ' ';
    
    	var items = theField.split(" ");
    	
    	for(var i=0;i<items.length;i++) {
    		if(items[i] == str) { document.getElementById('results').innerHTML += '<div>' + i + '</div>' }
    	}
    }
    </script>
    <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. Forecasters reported little relief in the days ahead, saying the weather system that brought the high temperatures could last well into next week.</div>
    <div id="mytext">If <a href="#" onclick="findMe('a');">a</a> record-breaking <a href="#" onclick="findMe('heat');">heat</a> wave doesn't lift soon, cattle rancher Sharon McDonald may see her hay crop turn to dust. Oppressive temperatures eased a bit <a href="#" onclick="findMe('Friday');">Friday</a> in some parts of the West, but McDonald's central Montana ranch baked under triple-digit heat. Forecasters reported little relief in the days ahead, saying the weather system that brought the high <a href="#" onclick="findMe('temperatures');">temperatures</a> could last well into next week.</div>
    <div id="results"></div>
    </body>
    </html>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #7
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    147
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Very, very well! It is exactly I was looking for!

    1) Ok. I will never to find these gaps!

    2) I have a database where all texts (remember other thread I put sometimes ago? ) are with hyperlinks - a large part of them. My difficult was do you did!

    3) Now I need rewriting some JS or ASP code for woreking with this hyptertext.

    I have some JS and ASP codes done, but for working with <textarea>. I hope to be able to change them!

    Thank you again.

    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
    •