SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how can I write a form variable with dynamic element?

    Hi guys,
    I am passing a value to a function, and then I want to use that value to update a form variable: eg:


    function update(type){
    document.forms.myform.type.value = 10;
    }

    Note, that type is the dynamic value for the form element that I
    want to update.

    but i cannot get it to work.

    any help is much appreciated.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function update(sType) {
         document.forms.myform[sType].value = 10;
    }
    You can eliminate the reference to the forms[] collection, if you like.

    The sType indicates 'string'; easier to keep track of data types.

    Everybody's favorite link.
    ::: certified wild guess :::

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for that.......you saved me lots of time!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •