Forum Moderators: open
i need a script that fetches the name of the first textarea on a page aswell as the name of the <form it is in...
thing is that i have a web portal with lots of different textareas (with different names) in different forms (with different names) on different pages.
now i would like to use some pre-done scripts for all of them, but they all require the name of the name of the form and the name of the textarea, like for example
if (document.form_name.textarea_name.value.length < 2) { ... } your help is very appreciated!
you could try something like
[pre]
function getFirstFormAndFirstTextarea()
{
var fs, i, nrf, nrt, tas, txt;
fs=document.forms;
tas=document.getElementsByTagName("textarea"); for (i=0; i<fs.length; i++)
{
nrf=i;
tas=document.getElementsByTagName("textarea");
for (i=0; i<tas.length; i++)
{
nrt=i;
break;
}
break;
}
if(fs.length==0) txt="doc contains no form";
else
{
txt="first form is form[" + nrf + "] ";
if(fs[nrf].name=='') txt+="without name";
else txt+=fs[nrf].name;
txt+="\n";
if(tas.length==0) txt+="form contains no textarea";
else
{
txt+="first textarea is tas[" + nrt + "] ";
if(tas[nrt].name=='') txt+="without name";
else txt+=tas[nrt].name;
}
}
alert(txt);
}
[/pre]
first of all: thx a lot!
now as i am a total newbie in javascript, now that i know the name of the first textfield on the page as well as the name of the form containing it, how do i use this information in the bbcode-code?
for example, on function is
function checkForm() {formErrors = false;
if (document.forumform.message.value.length < 2) {
formErrors = "Du musst zu deinem Beitrag einen Text eingeben.";
}
if (formErrors) {
alert(formErrors);
return false;
} else {
bbstyle(-1);
return true;
}
}
in there, "forumform" and "message" are the (up to now static) names of the form and the textarea. how do i replace those document.forumform.message occurences with me "dynamically" fetched form- and textarea-names?