How do I select specific dynamic form element in JavaScript

Sharky Forums


Results 1 to 2 of 2

Thread: How do I select specific dynamic form element in JavaScript

Threaded View

  1. #1
    Tiger Shark Pailin's Avatar
    Join Date
    Sep 2000
    Location
    East Grinstead, UK
    Posts
    621

    How do I select a specific dynamic form element in JavaScript

    In particular an <img>, which I don't think is considered an element, as if I do:

    var el = document.frmSuppMessage.elements;
    for(var i = 0 ; i < el.length ; ++i) {
    alert("El name ="+ el[i].name +".");
    }

    <img ...> tags do not show up?

    so I can't go through all elements and do a compare as I've done in the past :/

    Main point:

    The tag in question:

    <img SRC="../images/+.gif" name="img<%=rsOrd.Fields("Part_No")%>" onclick="this.src=hideRows('<%=rsOrd.Fields("Part_No")%>')">

    if I specify the exact name:
    alert("this="+ document.imgECL250.src + ".");

    gets me:
    this=http://SERVER/SITE/images/+.gif

    What I want to do is something like:

    function hideRows(rowIDs)
    {
    var imgToMod;
    imgToMod = "Buy" + rowIDs

    alert("this="+ document.imgToMod.src + ".");
    }

    which of course gets me:
    Error:'document.imgToMod.src' is null or not an object

    But I think you get what I'm trying to do...

    I can think of some sloppy hidden text input ways round this problem, but would love to know the smart way.

    Cheers, Pailin
    Last edited by Pailin; 06-12-2005 at 06:27 PM.
    Appreciate what you've got, but don’t dwell on it

    DFI LanParty UT RDX200CF-DR Crossfire
    Opteron 144 @ 2520MHz 1.6vcore
    pc4000 G.Skill Extreme Series Dual Channel 2GigKit
    3,4,4,8 1t
    Asus 8800GT
    4x HDD - 1.3TB
    Seasonic S12 500W Silent

Posting Permissions

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