Skip to Content
0
Former Member
Nov 04, 2005 at 09:40 PM

document.form.element.value

752 Views

Hi All,

I'm very new to javascript and had a quick question! Her is a sample of my code.

<script language="JavaScript" type="text/javascript">

function fnShowText(txt)

{

var x = document.getElementById(txt);

var e = document.getElementById(txt).name;

var sText = x.options.value;

var f = e.concat("b");

for (i=0; i<mainform.elements.length; i++)

if (mainform.elements<i>.name == f)

{

document.forms[0].elements<i>.value = sText;

}

}

</script>

I know what the value of elements is, but I want this script to be dynamic. Instead of looping through all the elements to find the value 'i' like I am currently doing it. This is bad response time. Is there a way to skip the looping and make this call dynamically if I already have the name of the element?

Thanks in advance!

Eric

By the way there is a 'i' after elements but for some reason it isn't showing up on this board.