Skip to Content
author's profile photo
Former Member

Dynamic Java Script Variable Setting

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Oct 06, 2005 at 01:55 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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