471,852 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

Javascript Adding Spaces Question

Does anyone know how I might add a function to this script that continually adds one space before and after the entire query (not in between every word though)?


If I type in the textarea: "hello there", before the Change button is clicked the string is " hello there ", and then it is parsed as such?



<script type = "text/javascript">

function replaceChars() {
var temp = document.subform.text.value;

temp = temp.replace(/hello there/gi, "goodbye there");
temp = temp.replace (/this/gi, "that");
temp = temp.replace (/today/gi, "tomorrow");

document.subform.text.value = temp;




<form name="subform">

<textarea rows="8" name="text" cols="31" value=""></textarea>
<input type=button name=action value="Change" onClick="replaceChars(document.subform.text.value) ;">



Aug 17 '07 #1
1 1532
16,027 Expert Mod 8TB
Please use code tags for posting code. Thanks!

Just add a space to beginning and end of the textarea value:
Expand|Select|Wrap|Line Numbers
  1. " " + document...value + " "
Aug 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Dana Smith | last post: by
1 post views Thread by Stephen | last post: by
136 posts views Thread by Matt Kruse | last post: by
21 posts views Thread by Martin Eyles | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.