JRS: In article <11**********************@g44g2000cwa.googlegroups .com>
, dated Mon, 6 Feb 2006 13:54:09 remote, seen in
news:comp.lang.javascript, Shamaila <SR****@opinionsite.com> posted :
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.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.