PDA

View Full Version : help with the generate function...


helpplease
01-27-2003, 06:19 PM
Hi! I would like to add another link that would generate some different text in the same textarea. Can anyone help?


<html>
<head>
<script language="JavaScript">

function generate(form)

{txt="Hello Example 1"

document.forms[0].output.value=txt

}

</script>

<body>
<form name=form>
<a onclick="generate(form)" href="#">one</a>
<textarea name="output" cols="60" rows=4 id="output"></textarea>
</form>
</body>
</html>

arnyinc
01-27-2003, 06:32 PM
This function allows you to pass the text from the link and it appends it to the existing text.


<html>
<head>
<script language="JavaScript">
function generate(formname, txt){
formname.output.value+=txt //get rid of the + sign to clear box each time
}
</script>

<body>
<form name="myform">
<a onclick="generate(document.myform, 'Hello Example 1')" href="#">one</a><br>
<a onclick="generate(document.myform, 'Second Text')" href="#">two</a><br>
<textarea name="output" cols="60" rows=4 id="output"></textarea>
</form>
</body>
</html>

helpplease
01-27-2003, 06:34 PM
Thanks so much!:p

helpplease
01-27-2003, 07:02 PM
Is there a way that I can use <b> and other attributes to the text that is being inserted into the field?

Jimbo
01-27-2003, 11:59 PM
<html>
<head>
<script language="JavaScript">
function generate(formname, txt){
formname.output.value=txt
}
</script>

<body>
<form name="myform">
<a onclick="generate(document.myform, '<b>Hello Example 1</b>')" href="#">one</a><br>
<a onclick="generate(document.myform, '<i>Second Text</i>')" href="#">two</a><br>
<textarea name="output" cols="60" rows=4 id="output"></textarea>
</form>
</body>
</html>

helpplease
01-28-2003, 12:02 AM
That does not seem to work. I tried it and it just writes in the <b> tags and does not make the text bold.
:confused:

Jimbo
01-28-2003, 12:14 AM
What was I thinking?! They best I can do is change the color of the text.
<hr>


<html>
<head>
<script language="JavaScript">
function generate(formname, txt, the_color){
formname.elements[0].value=txt
formname.elements[0].style.color=the_color
}
</script>

<body>
<form name="myform">
<a onclick="generate(document.myform, 'Hello Example 1', 'red')" href="#">one</a><br>
<a onclick="generate(document.myform, 'Second Text', 'blue')" href="#">two</a><br>
<textarea name="output" cols="60" rows=4 id="output"></textarea>
</form>
</body>
</html>

Jimbo
01-28-2003, 12:24 AM
If ya wanted to you could even change the background color with:




formname.elements[0].style.background=the_color