Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change an instance of an image

    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:

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.getElementById returns me the 1st image instead of the image of my current line...

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    I don't get it. Can you elaborate?

  • #5
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I have a table which looks like this for exemple:

    Code:
    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.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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

    Code:
    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:
    Code:
    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;
            }
    }


  •  

    Posting Permissions

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