Jump to content


Photo

document.variable.src - question for you


  • Please log in to reply
1 reply to this topic

#1 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 15 February 2006 - 03:53 AM

Hi all,

I'm working on a little javascript and I've come upon a lil' snag.

if ( picon == 0){
    //alert (srcimg);
document.imageinstruct1.src = 'ui/showhelp.gif';
}else{
document.imageinstruct1.src = 'ui/hidehelp.gif';
}

The part that I'm having a problem with is the document.variable.src, where I would like to use a variable that may have different values in that middle spot. As of now I can't get it to work, so I have to type in the actual name value of the image I want to swap. I don't want to have to write multple functions where one should do the trick. Is this possible? If so, what's the trick?

Another example would be:

var myvar = 'main';

document.myvar.src = 'image1.jpg';

Any ideas or suggestions?



#2 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 15 February 2006 - 06:12 AM

[!--quoteo(post=345932:date=Feb 14 2006, 10:53 PM:name=mmosel)--][div class=\'quotetop\']QUOTE(mmosel @ Feb 14 2006, 10:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi all,

I'm working on a little javascript and I've come upon a lil' snag.

if ( picon == 0){
    //alert (srcimg);
document.imageinstruct1.src = 'ui/showhelp.gif';
}else{
document.imageinstruct1.src = 'ui/hidehelp.gif';
}

The part that I'm having a problem with is the document.variable.src, where I would like to use a variable that may have different values in that middle spot. As of now I can't get it to work, so I have to type in the actual name value of the image I want to swap. I don't want to have to write multple functions where one should do the trick. Is this possible? If so, what's the trick?

Another example would be:

var myvar = 'main';

document.myvar.src = 'image1.jpg';

Any ideas or suggestions?
[/quote]


Well, I stumbled onto a solution. Instead of using the name tag I used the id tag, which allowed me to use this: document.getElementById(myvar).src = 'ui/showhelp.gif';

Works...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users