cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Java Script Variable Setting

Former Member
0 Kudos
181

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

It depends upon how u r calling the Javascript .

For example ,if the value of the txt is changing for each page refresh ..

set

txt = <% = bspvariablename %>

function fnShowText(txt)

{

var x = document.getElementById(txt);

var y = "select1b";

var sText = x.options.value;

document.mainform.select1b.value = sText;

}

Rgds,

J

Do Award pts if this is helpful.

athavanraja
Active Contributor
0 Kudos

just in the onclientselect of the dropdownlistbox run a javascript to set it for the inputfield.

onclientselect="javascript:myfunc(this.myform.<ddl id>.options[this.myform.<ddl id>.selectedIndex].value);"

<script>

myfunc(val){

document.myform.<inputfieldid>.value = val ;

}

</script>

Hope this helps.

Regards

Raja