...

View Full Version : As change <textarea> to <div> ?



lebronletchev
07-07-2007, 11:29 AM
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

lebronletchev
07-08-2007, 06:48 PM
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

Daemonspyre
07-09-2007, 01:32 PM
I am not sure what you are trying to accomplish, because the code above doesn't work.



<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:



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!

Daemonspyre
07-09-2007, 02:15 PM
As I promised (now that my coffee has kicked in... :))



<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>

lebronletchev
07-09-2007, 06:17 PM
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

Daemonspyre
07-09-2007, 06:59 PM
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!



<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>

lebronletchev
07-09-2007, 08:35 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum