• 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

[Javascript] Input into textarea with alerts

R4g1ng

New Member
You know that on here, when you click like the underline button, for example; an alert pops up asking what text you want to be underlined and then it puts it in the textarea with the bbcode tags. I'd like to do the same for my blog script but I don't know javascript at all. Can anyone help me? I know that its not limited to pre-scripted forums because I've seen a hand-coded one with the same code.
PS. If possible, I'd also like to know how to do the same with the url tags.
 
Well, in JavaScript you can't do "BB" code shortcuts, it is made in PHP and it is hard for a starter.

But I can help you to have an alertbox with a place to write something.

<HTML>
<SCRIPT language="JavaScript">

var string = prompt('Here the text or question.', 'here pre-entered text. '); //Initialize a new prompt

if ( (string==' ') || (string==null) ) //initializes if the string entered was empty
{
string="";
}
document.write(string) //Writes the string
</SCRIPT>
</HTML>
Hope you get the idea of what all is about.
 
Last edited:
I've got the BBCode, just need the code for the alert part.
Sorry if i sound stupid but I don't know that much Javascript. Where do I put the script and which parts do i need to edit? I mean, where do I define where to put the text?
 
Last edited:
Heres a more complete example,

Just modify your <FORM> so it has the OnSubmit part.
onSubmit="javascript:return doCheck(field1.value,field2.value)"

and add whatever fields u want in the javascript area.



HTML:
<script language="javascript">
<!--
function doCheck(field1,field2){
   if (field1 == "" || field1 == "ryza"){
		alert("Please enter field 1!");
		return false;
   }
   if (field2 == "" || field2 == "ryza"){
		alert("Please enter field 2!");
		return false;
   }
}
//-->
</script>

<form onSubmit="javascript:return doCheck(field1.value,field2.value)">
<INPUT TYPE="text" NAME="field1" value="">
<INPUT TYPE="text" NAME="field2" value="">
<INPUT TYPE="submit">
</form>
 
Last edited:
Umm..ryza, I don't think you understood my post properly. The code you posted validates fields, I could do that in PHP. What I want is the code for the alert boxes that puts the info inserted into the textarea, like on IPB and vBulletin (here).

EDIT: wait...I think I got it, except where do I define where to write what's inputted?
 
Last edited:
My previous code was still a little confusing. I made new code with a textarea, where the inputted string will be shown.
<HTML>
<SCRIPT language="JavaScript">
var string = prompt('Here the text or question.', '');

if ( (string==' ') || (string==null) )
{
string="";
}
document.write('<FORM>');
document.write('<textarea rows="9" name="test" cols="34">');
document.write(string);
document.write('</textarea>');
document.write('</FORM>');
</SCRIPT>
</HTML>

PS: I made some text red, you should only edit those unless you know what you are doing :p
 
Last edited:
Back
Top