...

View Full Version : Textbox question! please help!



afreeGaming
07-14-2003, 10:31 AM
I was woundering how i could get it so if a user presses a button it adds text to the textbox. For example, my game has a chatroom and I want to add bold, italic, underline images so when they click on them it adds "[B],[I] or [U]" to the textbox.

Know what i mean?

Spudhead
07-14-2003, 12:02 PM
You mean exactly the same as on vb Code for these forums? Well, a simple "view source" on the "Post a reply" page indicates that the "B" button is calling:

vbcode(this.form,'B','')

which, for my guess is in either vbcode_language.js or vbcode.js - which both get included a few lines above it. Download 'em, have a look.

Kor
07-15-2003, 02:07 PM
... or you want to know how can this be done in Java Script?

afreeGaming
07-22-2003, 01:12 AM
yeah in javascript, that vbcode reply does nothing for me...

Thanks for the try though spud.

Jason

PS: (somthing that works exactly like clicking the smilies when posting in the forum, and it inserts the code in the textbox)

any help appreciated :)

fredmv
07-22-2003, 01:29 AM
Pretty simple actually, just altering the value property of the input or textarea elements.

Here's an example script I just put together.



<script type = "text/javascript">
function add(t)
{
switch(t.toLowerCase())
{
case 'b':
document.f.t.value += "[.b]" + window.prompt('Enter the text you want to be bold:','') + "[./b]";
break;
case 'i':
document.f.t.value += "[.i]" + window.prompt('Enter the text you want to be italic:','') + "[./i]";
break;
case 'u':
document.f.t.value += "[.u]" + window.prompt('Enter the text you want to be underlined:','') + "[./u]";
break;
}
return;
}
</script>


That's the end of the actual JavaScript code. This uses the switch statement to check what we passed to the function. Next comes the HTML form:



<form name = "f">
<input type = "button" value = "Bold" onclick = "add('b');" />
<input type = "button" value = "Italic" onclick = "add('i');" />
<input type = "button" value = "Underlined" onclick = "add('u');" />
<textarea rows = "10" cols = "50" name = "t"></textarea>
</form>


Good luck!

Note: I put periods inside the "tags" so the vB code wouldn't kick in. Remove those and it should work nicely.

afreeGaming
07-22-2003, 02:48 AM
Thanks a lot, okay a few more questions if you dont mind me asking...

When pressing the Bold button, it starts the message box with...

"Script Prompt:" is there a way to change this caption?
Could we also do this to the caption of the messagebox itself?

That would be great, also, If i wanted to without a message box, how would i go about that?

Thanks again

Jason :thumbsup:

fredmv
07-22-2003, 02:52 AM
Yeah JavaScript puts that "script prompt" text there. There's just no way around it... Although, you could make it open a new window then by using the opener object, access the textarea within the form. You could also make it so it alters the visibility or display property of a textbox.

If you decide you want this, I could write the script for you and upload it.:D

afreeGaming
07-22-2003, 02:55 AM
Could you possibly contact me at e-mail deleted? I would like to show you what im doing, so possibly you could have the best insight on what the best possible options are available to me...

Else, if not possible, I would like to know also, how to insert the text without the command promt as well... (i will use the message boxes for Italic, underline, and bold, but not for smilies)

Jason

fredmv
07-22-2003, 02:57 AM
Alright, I emailed you.

afreeGaming
07-22-2003, 03:27 AM
Okay not sure if you got my mail, but...

When pressing cancel, it will display this in the textbox...

[.b]null[./b]

Is there a way to prevent this?

Jason



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum