Avatar of newbie29
newbie29
 asked on

ajax call on image onclick

Hello Folks,
I have a script which does ajax call on onclick event, attached is a block of snippet used to process all the records available on the page, all it does is on ajax call is to converts tick image to cross image or cross to tick image.
Currently the script converts all tick to cross and if they are already any cross image(s) it is converting them to tick.
The change I want is instead of changing all (croos and tick) images on the page, it should only tick the images which are crossed and ignore all those images which are ticked.
This problem probably because I am calling one function from the tick and cross images?
Hielo, you probably be the best person to assist me on  this as you already have seen the code earlier.
Thanks for any help guys.
Regards
Sam
function processAll()
         {
            //obtain list of <span class="id">
            var theIds = $("span.id");
     
            for(var i=0; i < theIds.length; ++i)
            {
                    var theImage = theIds[i].getElementsByTagName("img")[0];
                    var theId = theImage.className.replace("id_","");
                    //var theValue =  ( (theImage.src.indexOf("avail_yes") > -1) ? "Y":"N");
                    var theValue =  ( (theImage.src.indexOf("avail_yes") > -1) ? "N":"Y");
                    // ajax call
                    makeAjaxRequest(theId, theValue);
            }          
         }

Open in new window

JavaScript

Avatar of undefined
Last Comment
newbie29

8/22/2022 - Mon
Richard Quadling

Assuming that "theValue" is the indicator for tick/cross, then ...

if ('Y' == theValue) {
 makeAjaxRequest(theId, theValue);
}

maybe?
hielo

>>it should only tick the images which are crossed
See code below:
function processAll()
         {
            //obtain list of <span class="id">
            var theIds = $("span.id");
     
            for(var i=0; i < theIds.length; ++i)
            {
                    var theImage = theIds[i].getElementsByTagName("img")[0];
                    var theId = theImage.className.replace("id_","");
                    //var theValue =  ( (theImage.src.indexOf("avail_yes") > -1) ? "Y":"N");
                    var theValue =  ( (theImage.src.indexOf("avail_yes") > -1) ? "N":"Y");
                    if( theValue=="Y")
				{
					// ajax call
                    	makeAjaxRequest(theId, theValue);
				}
            }          
         }

Open in new window

newbie29

ASKER
Thanks Hielo,
Would you suggest me to create 2 different functions one for tick another for cross please?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
newbie29

ASKER
danke schon!