Skip to Content
0
Former Member
Oct 05, 2005 at 08:27 PM

Dynamic Java Script Variable Setting

149 Views

Hello!

I'm trying to set a value in Java Script dynamically and running in to some snags.

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

function fnShowText(txt)

{

var x = document.getElementById(txt);

var y = "select1b";

var sText = x.options.value;

document.mainform.select1b.value = sText;

}

</script>

On the last line "document.mainform.select1b.value = sText"

I want to be able to set this value dynamically. Meaning is there way to make the select1b part a variable? This select1b is an htmlb input field. I'm trying to set that to a selected value in a drop down box. This works if I type in the statement above. But when I try to code like this I have issues:

a = "select1b"

document.mainform.a.value = sText;

I understand that select1b is an object so this won't work, but any ideas on how I can try to implement this?

Thanks in advance,

Eric