• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

someone has to know - Javascript problem!

Polykranopalous

New Member
For my CMS i quickly put together I want to be able to add news without having to put actually html code inside the textarea (so i wanted it much like in this forum). I have setup the "BBCode" settings and such so it all works, but unfortunitly I have it where in the actual article you have to type "Hey this is [ b ]bold text[/ b ]. I have checked out a phpfreak tutorial and now I have the ability to use a button to make text bold/italic etc.

Now my problem lays in the URL button. The code for the buttons allow it so that when you click the URL button (or any button) the first time it displays [ url ] in the textarea and then the second time you click it, it will display the closing [ /url ] tag. BUT what I want it to be able to do is:

The first Time the URL button is hit it will display "[url http://" in the textarea. then the user can type the "site.com". Now when the user hits the button AGAIN it will place a "]" tag to close the url part and then the user can put in the text description like "My Site". Then the THIRD time the button is hit it will display the end code "[/ url ]".

I hope that didn't sound too confusing and made sense to someone because i really need help on this - Im not tooo big on javascript and this seems like an easy task.

Here is the code for the buttons I am using, and everything you will need to look at to help me with this problem:

Code:
<script type="text/javascript">
<!--
var url = 2;
function tag(v, tagadd, newbut, tagclose, oldbut, name) {
    if (eval(v)%2 == 0) {
        eval("window.document.editform."+name+".value = newbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagadd;
        window.document.editform.post.focus();
    } else {
        eval("window.document.editform."+name+".value = oldbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagclose;
        window.document.editform.post.focus();
    }
    eval(v+"++;");
}
-->
</script>
<form action="something" method="whatever" name="editform">
<input type="button" value="url" name="url" onclick="javascript:tag('url', '[ url=http://yoursite.com ]', 'url*', '[ /url ]', 'url', 'url');" />

<br>
<textarea name=post rows=5 cols=75></textarea></form>

That code works for 2 clicks, so first time its clicked it displays "[ url=http://yoursite.com ]" then user enters description and hits button again to display the end "[ / url ]", but the problem is then the user has to manually go back and edit the YOURSITE.COM to the desired url. If anyone can give me a hand I would much appreciate it - Thank You.
 
Back
Top