Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript formatting text string help

Status
Not open for further replies.

rickpill

Programmer
Feb 28, 2002
108
0
0
US
Hi,

I have an ASP application and I need some help in formatting a Javascript client side text string. I have the following 2 text fields passed from my asp application:

FIELD 1 Contains key word descriptions as follows:

*SALE*All participants in Sale#*COUNTRY*who reside in# etc.


FIELD 2 Contains user input:

SALE NY7698 COUNTRY US CA

Expected result:

All participants in Sale NY7698 who reside in US CA.

Thank you,

Rick




 
rickpill, can't you use a document.write() syntax to format the text??
EX: document.write(FIELD1 + FIELD2)

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
Yes, I could use document.write, but I need to substitute the user's input with text field 1 first. Text field 1 contains all possible key words, Text field 2 (user's input) does not.


Thanks,

Rick








 
are you trying to match words here?

Known is handfull, Unknown is worldfull
 
Using split to create an array
build your sub strings then replace??...

<html>
<head>
<title></title>
<script language=&quot;JavaScript&quot;>
var stra = new Array();
function sub_strg() {
d = document.test;
stra = d.rvals.value.split(&quot; &quot;);
str_sale = &quot; &quot; +stra[1]+ &quot; &quot;;
str_country = &quot; &quot; + stra[3] + &quot; &quot; + stra[4] + &quot; &quot;;
alert(str_sale);
alert(str_country);
strb = d.nwvalue.value;
strc = strb.replace(/\*SALE\*/,&quot;&quot;);
strc = strc.replace(/\#\*COUNTRY\*/,str_sale);
strc = strc.replace(/\# etc/,str_country);
d.nwvalue.value = strc;
}
</script>

</head>
<body>
<h2>After this that</h2><form name=&quot;test&quot;>
Start Values:<br>
<input type=&quot;text&quot; name=&quot;rvals&quot; size=&quot;35&quot;
value=&quot;SALE NY7698 COUNTRY US CA&quot;>
<br><br>New String:<br>
<input type=&quot;text&quot; name=&quot;nwvalue&quot; size=&quot;50&quot;
value=&quot;*SALE*All participants in Sale#*COUNTRY*who
reside in# etc.&quot;>
<a href=&quot;javascript:sub_strg()&quot;>Split, Replace Test</a>
</body>
</html>



2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top