manix Posted June 23, 2011 Share Posted June 23, 2011 Hey.. I've been struggling with this for a while now and I still can't figure it out.. What I want to do is, have a nice little edit panel under the comment section which the user can use while writing a comment, kinda something like the one in all the forums and sites, having the bold butotn italic button underlined button and others, but a little bit different: When the user clicks a button once in his textarea the tag is being opened and the button remains clicked and when the user clicks it again the tag is being closed and the button's image is changed back to normal, but I completely failed in my attempts to do that simple looking function and I'm really getting pissed already. I'd show you my code if you like but I really prefer not to because it's unbelievably embarrassing ;s Thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/240190-bold-italic-etc/ Share on other sites More sharing options...
AMcHarg Posted June 23, 2011 Share Posted June 23, 2011 It can be done with Javascript. You could alternate a value that the button reads and changes each time it is pressed. If the value is 0 then it can insert [ b ] into the text area (and then change the value to 1), and if it's 1 then it can insert [ /b ] into the text area (and then change the value back to 0 again). Link to comment https://forums.phpfreaks.com/topic/240190-bold-italic-etc/#findComment-1233757 Share on other sites More sharing options...
AMcHarg Posted June 23, 2011 Share Posted June 23, 2011 Incidentally, this should be moved to a forum area where Javascript is the designated topic. Link to comment https://forums.phpfreaks.com/topic/240190-bold-italic-etc/#findComment-1233758 Share on other sites More sharing options...
manix Posted June 23, 2011 Author Share Posted June 23, 2011 yes that's my idea too but I failed to do it in PHP, and since I'm not rly familiar with javascript at all I posted here if you could give me a solution, if not I guess I'm going to have to familiarize with java here's my failz0red code anyway <form name="izrot"> <textarea name="pole"></textarea> <?php $imgname="Bold1.jpg";$inputstring[1]="<b>";$inputstring[2]="</b>";$bold=2; echo "<img src='buttons/Bold1.jpg' name='bold' onmouseover='if($bold=1){$bold=2;}else{$bold=1;}' onclick='izrot.pole.value=izrot.pole.value + $inputstring[$bold]'/>"; ?> </form> And yes, I know the image isn't being changed but if I manage to succeed in making it insert the tag, the image wont be a problem. Link to comment https://forums.phpfreaks.com/topic/240190-bold-italic-etc/#findComment-1233759 Share on other sites More sharing options...
AMcHarg Posted June 23, 2011 Share Posted June 23, 2011 PHP is server-side, you can't achieve what you want with it. Note as well that Java and Javascript are completely different things. To do this you want to use Javascript, not Java. Good luck. Link to comment https://forums.phpfreaks.com/topic/240190-bold-italic-etc/#findComment-1233782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.