Click to See Complete Forum and Search --> : button inserts text into textarea
instantnet
12-30-2002, 10:40 PM
Hello,
I am in need of 2 things. A simple script that will insert specified code into a text area and a simplified code that will take a propt froma user and combie with with predefined text and then insert it into the text area. Much like the forum buttons here. I would go through it but it always turns up buggy. Thanks!
AdamBrill
12-30-2002, 11:13 PM
Something like this should work:
<html>
<head>
<script language=javascript>
function AddText()
{
UserInput=window.prompt("Text to add?","");
text=""
text+="Add this text!\n";
text+="And this text!\n";
text+=UserInput;
document.form1.TextBox.value=text;
}
</script>
</head>
<body>
<form name="form1">
<textarea rows="10" name="TextBox" cols="40"></textarea></p>
<p><input type="button" value="Button" onClick="AddText();" name="B3"></p>
</form>
</body>
</html>
That should do it for you...
instantnet
12-31-2002, 12:12 AM
Dave- Thanks. The script is very simple! Now how do we replace it with a image of our choice?
AdamBrill- Thanks! 1) How could I press that button more than once for a given text area? ex <b>Bold this</b> <B>bld that</B> 2) I figured that I would take out the /n for all on one line however if I wanted each on it own line where do you put the /n on the user input line?
<script language=javascript>
function AddText()
{
UserInput=window.prompt("Text to add?","");
text=""
text+="Add this text!\n";
text+=UserInput;
text+="And this text!\n";
document.form1.TextBox.value=text;
}
</script>
3) I think this should work for the image...
<a href="Javascript:AddText();" tabindex="-1">
<img src="button.gif" width="23" height="22" border="0" alt="alttxt" title="titletxt" align="top" /></a>
instantnet
12-31-2002, 02:13 PM
Here we go! I got it. Perhaps someone can think of cleaner code for the one that has to go into the head? Now all I have left loking for is a pulldown menu that will add the value of the selected. Example the font box used in this fourm.
so I would like TEXT + Selection +TEXT and the have it revert to the first selector.
Here is the code for the others... Thanks!
Without A Prompt---using an image instead of a button
<a onclick="document.reply.message.value += '?';return true;" ><img alt="alttext" src="some.gif"></a>
Without a prompt-as a button
<input type="button" value="?" onclick="this.form.T1.value += '?';return true;">
[font=Arial][/font=Arial][font=Andale Mono][/font=Andale Mono][size=1][/size=1]
With a Prompt --- using an image instead of a button(May not be the cleanest script in the world)
Place in head...
<script language="JavaScript">
<!-- hide script from non java browsers
function x () {
return;
}
function DoPrompt(action) {
var revisedMessage;
var currentMessage = document.reply.message.value;
if (action == "bold") {
var thisBold = prompt("Enter the text to format.", "");
var urlBBCode = "<b>"+thisBold+"</b>";
revisedMessage = currentMessage+urlBBCode;
document.reply.message.value=revisedMessage;
document.reply.message.focus();
return;
}
}
//-->
</script>
Then this is the image... for the above code
<a onclick="DoPrompt('bold');" href="javascript:%20x()"><img alt="altname" src="some.gif">