Forum Moderators: open

Message Too Old, No Replies

Adding BB Code to Comments Box

Slight issue..

         

dreamcatcher

12:32 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys,

Hope you can help me with this. I have a guestbook script where I can add BB Code using an onclick. This works fine and this is the code I have:


function add_bb_code(gbookCode)
{
var gbookCode;
var newMessage;
var oldMessage = document.MyForm.comments.value;
newMessage = oldMessage + gbookCode;

document.MyForm.comments.value=newMessage;
document.MyForm.comments.focus();

return;
}

So, I use onclick="add_bb_code('[*b][*/b]')"

etc

That works fine.

However, if I refresh the form, ie, to preview the entry and then click to add more BB code, it doesn`t work. This error is in the javascript console:

document.MyForm.comments.focus is not a function

Any ideas?

Thanks,

dc

coopster

6:14 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Simple question, but it has to be asked. You do have a "name" attribute on your form, correct? "MyForm"?

dreamcatcher

9:31 am on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, Coop, I do indeed. Like I say, it works fine initially, but when I refresh, then it doesn`t. I can`t understand it because its the same page/form re-loading.

In fact I get this problem all the time, with virtually all javascript. I can get some code directly from Dynamic Drive, implement it and its ok. But when I refresh a page and load the same form, never works. Well, hardly ever works.

I have tried it in 4 browsers. Same in all. :(

coopster

4:23 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't know what to tell you here, haven't a clue. It works fine for me. Is it something else in the document? A caching issue of sorts or something it seems like ...

dreamcatcher

9:36 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh well, I`ll just have to re-do things to forget the refresh. Maybe just have a link back to the previous page or something.

Thanks Coop.

:)