Add text...don't replace it

 
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions
View previous topic :: View next topic  
Author Message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 1:03 am    Post subject: Add text...don't replace it Reply with quote

Okay i'm trying to make a guestbook type thing and i am adding smilie code things but the problem is when they select a smilie, it replaces all the text in the message box instead of adding it...how do i make it add and not replace??

Its currently:
<textarea cols=5 rows=30 name=message>.....
....the smilie code is..
<img src=/smilies/smile.gif onClick=guestbook.message.value="*smile*">
...but that replaces the whole value..so how do i fix that..
Back to top View user's profile Send private message Visit poster's website AIM Address
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 1:41 am    Post subject: Reply with quote

Yea it will because your telling it to do just that.

you need to add the value or string to the value of the textarea, so instead of assigning it a value you need to use the '+=' to add the string and not assign with an '='.
Back to top View user's profile Send private message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 1:45 am    Post subject: Reply with quote

ok...so u mean
<img src=/smilies/smile.gif onClick=guestbook.message.value+="*smile*">
??
caz that just did the same thing..
Back to top View user's profile Send private message Visit poster's website AIM Address
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 1:52 am    Post subject: Reply with quote

Without sitting down and trying to hack some code together, you need to put the onClick event into a function

something like....
<script>
function addSmile(pValue){
tmpValue=guestbook.message.value; // place holder
tmpValue+=pValue; // add the passed value pValue to the place holder value
guestbook.message.value=tmpValue; // re-assign the new value
}
</script>

where pValue would be the string that you want addes, eg "*smile*"

this then makes the onClick call look like...

onClick=addSmile("*smile*")

but you will have to tinker with it but it shows a simple way of passing a vlaue to a function and the existing value of a textarea gets stored, added to and re assigned to the original textarea value.
Back to top View user's profile Send private message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 2:06 am    Post subject: Reply with quote

yeah...but in the PHP action...it does a
str_replace("*smile*", "<img src=/smilies/smile.gif", $message)
Back to top View user's profile Send private message Visit poster's website AIM Address
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 2:22 am    Post subject: Reply with quote

javascript and php are two different languages, in your original problem your using javascript event handler to assign a javascript object with a string value.

You can use PHP to generate the page content including the client-side javascript to help pre-format or validate the form on the clients computer prior to being passed to the server for processing.

You cant however get PHP to run on the clients machine because it is a server-side language.
Back to top View user's profile Send private message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 2:27 am    Post subject: Reply with quote

yeah..the original pattern was a form with action of putbookdata.php
then that processes it and replaces the *smile* with the real image....
Back to top View user's profile Send private message Visit poster's website AIM Address
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 2:37 am    Post subject: Reply with quote

Thing is... Did it solve your problem?
Back to top View user's profile Send private message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 2:45 am    Post subject: Reply with quote

no it did not...now its completely just not working
Back to top View user's profile Send private message Visit poster's website AIM Address
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Aug 18, 2004 4:14 am    Post subject: Reply with quote

Their is an error in the actual str_replace() thats why it failed to work , you
forgot to close the image tag with a > , the proper code is below this msg.

Code:
str_replace ("*smile*", "<img src='image.gif'>", $message);
Back to top View user's profile Send private message Visit poster's website
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Wed Aug 18, 2004 4:28 am    Post subject: Reply with quote

uh actually i just forgot to put that in the post...
Back to top View user's profile Send private message Visit poster's website AIM Address
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 10:15 am    Post subject: Reply with quote

? So is it a PHP thing or a Javascript thing?

I would advise that you first of all ensure that your javascript is functioning by firstly rendering your pages in a standard HTML page and test out the pages javascript functions, when your certain that you have solved the issues over the scripts running, you then can PHP them, it is no use trying to script a PHP to generate javascript unless your 100% confident that you can code 100% perfect otherwise you only compound your scripts errors, all it takes is a simple ; , = - + . ' or ", something unexpected or a character in the wrong place and your site comes crashing down.

example, which one is correct?

strValue="<strong><font color=\"#000000\" size=\"1\" face=\"Arial\"> some text here </font></strong>"

or is

strValue="<strong><font color="#000000" size="1" face="Arial"> some text here </font></strong>"

correct?

then mix that with PHP script to generate the correct line of code. Ever tried using javascript to write javascript?
Back to top View user's profile Send private message
senshi
-


Joined: 05 Nov 2003
Posts: 385
Location: UK

PostPosted: Wed Aug 18, 2004 10:28 am    Post subject: Reply with quote

soz, hit submit by mistake... but...

then if you want to make the data like colour and size, etc as variables, you further compound the '"'s issue when using javascript to make the result more flexable, you end up with

strValue="<strong><font color=\""+colValue+"\" size=\""+sizeValue+"\" face=\""+fontValue+"\"> some text here </font></strong>"

as a result, so coding javascript from PHP is at best from my point of view a lost cause unless your like I said 100% confident you can code error free.
Back to top View user's profile Send private message
webserver5555
-


Joined: 24 Apr 2004
Posts: 27
Location: Here

PostPosted: Thu Aug 19, 2004 2:07 am    Post subject: Reply with quote

Okay...btw TRUSTPunk helped me..so its working now
Back to top View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group