Jump to content

Rich Text Editor Trouble


dooper3

Recommended Posts

I am trying to use js to make a phpBB-style text editor for my website, and i've got it to put in the opening tags when the buttons are clicked, but for some reason it won't put in the closing tags. I think it may be because I am trying to alter the same onclick that calls the function. The code for the function is shown below:

[code]function addtags(styling,condition) {
if (condition == "open") {
document.getElementById(styling).onclick="addtags('"+styling+"','close')"
currenttext = document.getElementById('inputarea').innerHTML
document.getElementById('inputarea').innerHTML=currenttext+"["+styling+"]"
document.getElementById('inputarea').focus()
} else {
document.getElementById(styling).onclick="addtags('"+styling+"','open')"
currenttext = document.getElementById('inputarea').innerHTML
document.getElementById('inputarea').innerHTML=currenttext+"[/"+styling+"]"
document.getElementById('inputarea').focus()
}
}
</script>[/code]

Any ideas? Thanks!
Link to comment
Share on other sites

at the moment it will output the opening [heading] or [b] tags, but not the closing ones. The idea is that the input buttons each have an onclick="('open','heading'). They all start as open, and obviously heading corresponds to whichever button it is. Then when the button is clicked, the function shown before should check whether the brackets are already open by looking for "open" or "close", then do that before changing the onclick to ('close','heading') or whichever was clicked. But at the moment, it will open them, but doesn't like to change them to close (which I guess is down to the fact that the very onclick I am trying to edit is the one that called the function??). Also, it seems to stop the script working for that button aswell - if I try and click it again when the open bit has been done once, nothing happens, but the other buttons will still do the open, then stop working as well. There's no little yellow exclamation mark in IE like their usually is when the browser can't work out the JS. Help!
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.