/    Sign up×
Community /Pin to ProfileBookmark

[URGENT] help needed……see code inside

hi…
needed ur help urgently.
I am using a text area in which user is reqd to input values like this :

asdasd,asdas,fg,dfgdf,gfdg

through java script i am converting this to :
asdasd’,’asdas’,’fg’,’dfgdf’,’gfdg

but now my problem is that I dont want user to input ,(comma) in front and back and also i want that ‘(single quote) should automatically be appended to front and back like this:
‘asdasd’,’asdas’,’fg’,’dfgdf’,’gfdg’

please help me in doing this:

here is the code………

<HTML>
<HEAD>
<script type=”text/javascript”>

function convert(){
var re=/[,]/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
}

function replacechar(match){
if (match==”,”)
return “‘,'”

}

</script>
</HEAD>
<BODY>

<form >
<textarea name=”data1″ style=”width: 400px; height: 100px”></textarea><br />

<input type=”button” onClick=”convert(this.form.data1)” value=”Convert “>
</form>
</body>
</HEAD>
</HTML>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@BigMoosieAug 31.2005 — simply concatenate them:

"'" + arguments[i].value.replace(re, function(m){return replacechar(m)}) + "'"



But what do you want to happen if a quote is entered? Remove it? Replace with ' or " or alert the user?
Copy linkTweet thisAlerts:
@kaleenaauthorAug 31.2005 — simply concatenate them:

"'" + arguments[i].value.replace(re, function(m){return replacechar(m)}) + "'"



But what do you want to happen if a quote is entered? Remove it? Replace with ' or " or alert the user?
[/QUOTE]




can you provide the example of concatenation in my code.
Copy linkTweet thisAlerts:
@kaleenaauthorAug 31.2005 — ohh... sorry i got it...actually i was bit tensed.............

anyways thanks........

i want to remove the commas entered in front and back of the entered text like if user entered this:

,asd,sadsa,fdsf,

i should get this on submit


asd,sadsa,fdsf
Copy linkTweet thisAlerts:
@JPnycAug 31.2005 — He did. This is it:

"'" + arguments[i].value.replace(re, function(m){return replacechar(m)}) + "'"



The + sign is the concatenation operator in Javascript, as well as the addition operator.
Copy linkTweet thisAlerts:
@kaleenaauthorAug 31.2005 — i did another change in the code,


<textarea name="data1" style="width: 400px; height: 100px" onchange="convert(this)"></textarea><br />

now whenever i m using tab, i m facing this problem.............if on tab change the data is:

'asd','asd','asd', on tab change it is becoming ''asd'',''asd'',''asd''

how can i preven t this.i want to use the function inside text area as there are many text areas in my original screen.
×

Success!

Help @kaleena spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...