Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on 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 a 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.