Forum Moderators: open

Message Too Old, No Replies

Writing Javascript to a specific form

using form id

         

CNibbana

4:54 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



I have more than one text area form on my page, and I am trying to the following javascript to write only within a specific form with <form id="here">. How do I tell this javascript to write only within this text area? Currently it writes in the first text area found on the page.

var tl=new Array(
"text to go in form appears here."
);

var speed=60;
var index=0; text_pos=0;
var str_length=tl[0].length;
var contents, row;

function type_text()
{
contents='';
row=Math.max(0,index-7);
while(row<index)
contents += tl[row++] + '\r\n';
document.forms[0].elements[0].value = contents + tl[index].substring(0,text_pos) + "_";
if(text_pos++==str_length)
{
text_pos=0;
index++;
if(index!=tl.length)
{
str_length=tl[index].length;
setTimeout("type_text()",1500);
}
} else
setTimeout("type_text()",speed);

and the html if necessary:

<form id="here">
<script language="javascript"><!--
document.onload = type_text();//--></script>
<textarea rows=8 cols=55 wrap=soft></textarea>
</form>

steelegbr

5:17 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Try replacing

document.forms[0].elements[0].value

With

document.here.elements[0].value

You also may have to edit the FORM tag to

<FORM ID = "here" NAME = "here">