Results 1 to 5 of 5

Thread: dynamically change image source

  1. #1
    Join Date
    Mar 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default dynamically change image source

    i have a tabular form with several of the following:

    <A HREF="javascript:genCal_X()">< img src="cal.gif" border="0" /></DIV></A>

    where the _X refers the to the row. I am able to retrieve and dynamically change the href value using the following:

    var links=document.getElementsByTagName('A');
    calExp = new RegExp("genCal_"+calRow);
    for (var i=0;i<links.length;i++) {
    if (links[i].href.match(calExp)) {
    links[i].href="javascript:void(0);";
    }
    }

    i want to be able to change the image source as well but am not sure how to gaurantee i change the one associated to the changed href value...
    Last edited by rizlaa; 10-03-2006 at 11:01 AM.

  2. #2
    Join Date
    Mar 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    have tried the following:

    var links=document.getElementsByTagName('A');
    calExp = new RegExp("genCal_"+calRow);
    srcExp = new RegExp("cal.gif");
    for (var i=0;i<links.length;i++) {
    if (links[i].href.match(calExp)) {
    links[i].href="javascript:void(0);";
    links[i].innerHTML = links[i].innerHTML.replace(srcExp, "newIMG.gif");
    }
    }

    this works but the innerHTML does not like the lone </DIV> it automatically places a <DIV> tag in front of it thereby adding an additional blank line.

    any idea how i can over come this <DIV> tag addition??
    (the code is generated by a wizard and so i have to live with the way it is generated)

  3. #3
    Join Date
    Oct 2005
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    exactly why do you have a </div> without a <div> somewhere infront of it?

  4. #4
    Join Date
    Mar 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The wizard generates <DIV> tag in front of the <A> tag along with a bit of other code. It does this to be able to cater for various scenarios.

    I am not able to change the way the code is generated. just need to be able to manipulate it. I'm hoping there is a way of using innerHTML with just a </DIV>??

  5. #5
    Join Date
    Mar 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the following works!!
    var links=document.getElementsByTagName('A');
    calExp = new RegExp("genCal_"+calRow);
    srcExp = new RegExp("cal.gif");
    for (var i=0;i<links.length;i++) {
    if (links[i].href.match(calExp)) {
    links[i].href="javascript:void(0);";
    links[i].firstChild.src = links[i].firstChild.src.replace(srcExp, "newIMG.gif");
    }
    }

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
  •