Text areas in html implementing using javascript

S

SRafiq

Hi I need help with a topic I have an html page and in it i have a
textarea which can have a multiple of info, is there any possible way
that i can out put a specific area of the textarea using javascript or
no its not possible.
 
M

McKirahan

Hi I need help with a topic I have an html page and in it i have a
textarea which can have a multiple of info, is there any possible way
that i can out put a specific area of the textarea using javascript or
no its not possible.

It's not clear what you're asking for.

Say you have:

<textarea name="ta" id="ta" cols="40" rows="10">Go Cubs!</textarea>

Are you asking how you could extract,say, just "Cubs" from it?

If so, then a few questions:

1) What do you want to extract?
Is the the same word or phrase each time?

2) What do you want to do with it?
Just store in a JavaScript variable?
 
S

Shamaila

I) its not the same text or phrase, i wish it was but its not.
2) I want to be able to pull that one word or phrase and set it to be
equal to a variable, and out put it in another location.

Please help
 
M

McKirahan

Shamaila said:
I) its not the same text or phrase, i wish it was but its not.
2) I want to be able to pull that one word or phrase and set it to be
equal to a variable, and out put it in another location.

Please help

I am still having trouble understand exactly what you want to do.

Could you provide a very detailed example? You started with:

"Hi I need help with a topic I have an html page and in it i have a
textarea which can have a multiple of info, is there any possible way
that i can out put a specific area of the textarea using javascript or
no its not possible."

a) "I have an html page ..."; is it your page (or a URL)?

b) Does the page contain a <form> with a <textarea>?

c) What would determine "a specific area of the textarea"?

Is the following even close to what you want?

<html>
<head>
<title>ta.htm</title>
<script type="text/javascript">
function ta() {
var form = document.form1;
var area = form.area1.value;
if (area == "") return;
var word = "hello";
var what = area.toLowerCase();
if (what.indexOf(word) < 0) return;
alert("The word '" + word + "' is in the textarea.");
}
</script>
</head>
<body>
<form name="form1">
<textarea name="area1" cols="40" rows="8">Hello World!</textarea>
<input type="button" value="Click" onclick="ta()">
</form>
</body>
</html>
 
S

Shamaila

Hi thanx or the help, ok let me start over. I work for a marketing
research firm, we have a survey, with various questions and one of the
open-ended questions of course consists of a text area. lets say
some one entered, Bear doll candy, i want to be able to take each of
these words and somehow make them into variables so i can call on these
variables later in the survey. does that make more sense, i hope it
does.
 
M

McKirahan

Shamaila said:
Hi thanx or the help, ok let me start over. I work for a marketing
research firm, we have a survey, with various questions and one of the
open-ended questions of course consists of a text area. lets say
some one entered, Bear doll candy, i want to be able to take each of
these words and somehow make them into variables so i can call on these
variables later in the survey. does that make more sense, i hope it
does.

Better -- but I would think you would want to do this on the server
instead of the client; if so, what technology will you use: ASP, CGI, or ?

Here's a client-side approach that may give you some ideas.

<html>
<head>
<title>ta_words.htm</title>
<script type="text/javascript">
function ta() {
var form = document.form1;
var area = form.area1.value;
if (area == "") return;
var list = area.match(/\w+/g);
var what = "Words in the textarea:";
for (var i=0; i<list.length; i++) {
what += "\n" + (i+1) + ". " + list;
}
alert(what);
}
</script>
</head>
<body>
<form name="form1">
<textarea name="area1" cols="40" rows="8">
I like Bear doll candy.</textarea>
<input type="button" value="Click" onclick="ta()">
</form>
</body>
</html>
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Mon, 6 Feb 2006 13:54:09 remote, seen in
news:comp.lang.javascript said:
Hi thanx or the help, ok let me start over. I work for a marketing
research firm, we have a survey, with various questions and one of the
open-ended questions of course consists of a text area. lets say
some one entered, Bear doll candy, i want to be able to take each of
these words and somehow make them into variables so i can call on these
variables later in the survey. does that make more sense, i hope it
does.

Let the textarea be named TA. Then

eval(TA.value.replace(/(\w+)/g, " var $1 ; "))

will do what you ask for, assuming that the words are separated by
whitespace. I don't know how you expect to use the variables, though.

Demonstration :

TA = "aaa bbb cc"
S = TA.replace(/(\w+)/g, "var $1 ; ")
// var aaa ; var bbb ; var cc ;


Or S = "var " + TA.replace(/(\w+)/g, "$1,") + " X ;"
// -> "var " + TA.replace(/(\w+)/g, "$1,") + " X ;"

where X is a dummy.


However, ISTM that you should advise your firm to employ a genuine
programmer for writing survey analysis code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top