...

View Full Version : Change an instance of an image



Norin
05-10-2007, 07:54 PM
Hello,
I have a table containing lines with two combobox and an image. Actually, I am able to change the 2nd combobox when the 1st one is modified but I cant acces my image.

I tried to use document.getElementById but it simply changes the image of the first line instead of the image of the current line...

Here is my javascript code:



function changeAffProchEtape(strEtat, objForm)
{
objTxt_NO = objForm.etapeSuivante_NO;
objCb_RE_RP = objForm.etapeSuivante_RE_RP;
objStatus = objForm.imageUser;

strPath = document.getElementById('path').value;

switch(strEtat)
{
// 'NO' = Normal
case 'NO' :
objTxt_NO.style.display = "block";
objCb_RE_RP.style.display = "none";
objStatus.style.visibility = 'visible'
objStatus.src = strPath + "/images/users.gif";
break;
}
}


As you can see, I am passing my form by parameter which allows me to get my combobox (etapeSuivante_NO & etapeSuivante_RE_RP) but I cant acces my "imageUser" (which is a <input type="image">) this way...

Anyone could help me please?

Thanks

glenngv
05-10-2007, 09:48 PM
Input image is not a form control even though it is an input tag. Just put an id to it and access it by document.getElementById

Norin
05-10-2007, 10:27 PM
document.getElementById returns me the 1st image instead of the image of my current line...

glenngv
05-10-2007, 10:32 PM
I don't get it. Can you elaborate?

Norin
05-11-2007, 02:20 PM
Well, I have a table which looks like this for exemple:



1 | CBO1 | CBO2 | IMG
----------------------
2 | CBO1 | CBO2 | IMG
----------------------
3 | CBO1 | CBO2 | IMG


When the user modify the CBO1, the CBO2 and the IMG of the same line than the CBO1 he just modified must be changed.

If I use a document.getElementById, it just get the IMG of the first line instead of the IMG of the line where the CBO1 has been modified.

glenngv
05-11-2007, 09:03 PM
Do you follow a naming pattern to your fields so that the script can identify which row you are modifying? If you put the combo box names and image ids like below


etapeSuivante_NO1 | etapeSuivante_RE_RP1 | imageUser1
etapeSuivante_NO2 | etapeSuivante_RE_RP2 | imageUser2
etapeSuivante_NO3 | etapeSuivante_RE_RP3 | imageUser3
then, the script would look like this:

function changeAffProchEtape(strEtat, objForm, suffix)
{
var objTxt_NO = objForm.elements["etapeSuivante_NO" + suffix];
var objCb_RE_RP = objForm.elements["etapeSuivante_RE_RP" + suffix];
var objStatus = document.getElementById("imageUser" + suffix);

var strPath = document.getElementById('path').value;

switch(strEtat)
{
// 'NO' = Normal
case 'NO' :
objTxt_NO.style.display = "block";
objCb_RE_RP.style.display = "none";
objStatus.style.visibility = 'visible'
objStatus.src = strPath + "/images/users.gif";
break;
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum