harry_bela
asked on
Text area insert html code if certain letters entered.
Hi.
I want to setup a really simple forum type post script and am a bit stuck on the following.
I have a 1 x textarea on and 1 x button
What to happen is when the users enters text and then special pre-defined letter arragments like :-) or :( (smilies basically) on submit the letter arragments is repalced with html code (effectively a find and replace) which will show the smilie image associated with that text.
So the user enters
This is just a test :-)
on submit would become
This is just a test <img src="./images/smilie1.gif" >
or
This is just a test ;-)
= This is just a test <img src="./images/smilie8.gif" >
etc... etc...
Their may be lots of smilies so i need to be able to enter multiple variables in the function.
Can anyone help and post the complete working proof of concept code?
Many thanks
Harry.
I want to setup a really simple forum type post script and am a bit stuck on the following.
I have a 1 x textarea on and 1 x button
What to happen is when the users enters text and then special pre-defined letter arragments like :-) or :( (smilies basically) on submit the letter arragments is repalced with html code (effectively a find and replace) which will show the smilie image associated with that text.
So the user enters
This is just a test :-)
on submit would become
This is just a test <img src="./images/smilie1.gif"
or
This is just a test ;-)
= This is just a test <img src="./images/smilie8.gif"
etc... etc...
Their may be lots of smilies so i need to be able to enter multiple variables in the function.
Can anyone help and post the complete working proof of concept code?
Many thanks
Harry.
what server side scripting are you using for your forum?? ASP, PHP, .NET???
if ASP then here is a function
function CahngeSmile(what)
dim smiles
smiles = Array(":-)",":(",":)",":-( ",":-p",": -O")
for i = 0 to Ubound(smiles)
select case i
case 0:
Replace(what,smiles(i),"<i mg src='./images/smilie1.gif' >")
case 1:
Replace(what,smiles(i),"<i mg src='./images/smilie2.gif' >")
case 2:
Replace(what,smiles(i),"<i mg src='./images/smilie3.gif' >")
case 3:
Replace(what,smiles(i),"<i mg src='./images/smilie4.gif' >")
case 4:
Replace(what,smiles(i),"<i mg src='./images/smilie5.gif' >")
case 5:
Replace(what,smiles(i),"<i mg src='./images/smilie6.gif' >")
end select
next
end function
then to action this all you do is this. Assuming your server side scripting is asp then when you retrieve the text from the user's submited post, just place it is like this
dim userData
userData = CahngeSmile(request.form(" YourTextAr eaName"))
function CahngeSmile(what)
dim smiles
smiles = Array(":-)",":(",":)",":-(
for i = 0 to Ubound(smiles)
select case i
case 0:
Replace(what,smiles(i),"<i
case 1:
Replace(what,smiles(i),"<i
case 2:
Replace(what,smiles(i),"<i
case 3:
Replace(what,smiles(i),"<i
case 4:
Replace(what,smiles(i),"<i
case 5:
Replace(what,smiles(i),"<i
end select
next
end function
then to action this all you do is this. Assuming your server side scripting is asp then when you retrieve the text from the user's submited post, just place it is like this
dim userData
userData = CahngeSmile(request.form("
lol missed out the vital part. Here it is corrected. Just a suggestion
function CahngeSmile(what)
dim smiles
smiles = Array(":-)",":(",":)",":-( ",":-p",": -O")
for i = 0 to Ubound(smiles)
select case i
case 0:
Replace(what,smiles(i),"<i mg src='./images/smilie1.gif' >")
case 1:
Replace(what,smiles(i),"<i mg src='./images/smilie2.gif' >")
case 2:
Replace(what,smiles(i),"<i mg src='./images/smilie3.gif' >")
case 3:
Replace(what,smiles(i),"<i mg src='./images/smilie4.gif' >")
case 4:
Replace(what,smiles(i),"<i mg src='./images/smilie5.gif' >")
case 5:
Replace(what,smiles(i),"<i mg src='./images/smilie6.gif' >")
end select
next
CahngeSmile = what
end function
function CahngeSmile(what)
dim smiles
smiles = Array(":-)",":(",":)",":-(
for i = 0 to Ubound(smiles)
select case i
case 0:
Replace(what,smiles(i),"<i
case 1:
Replace(what,smiles(i),"<i
case 2:
Replace(what,smiles(i),"<i
case 3:
Replace(what,smiles(i),"<i
case 4:
Replace(what,smiles(i),"<i
case 5:
Replace(what,smiles(i),"<i
end select
next
CahngeSmile = what
end function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Super Thanks Andy.
Harry B.
Harry B.