Click to See Complete Forum and Search --> : onClick value setting problem


sumyounguy
07-21-2003, 05:00 PM
I have the following code:

onclick="'+(clicked ? clicked=false:clicked=true)+';'+(clicked ? itemID+'img.src=\'up.gif\'' : itemID+'img.src=\'down.gif\'')+'"

it should be added to a div/layer
I'm wondering if there is something in there that could cause clicked to not chage from true to false every time, because I've got this code running on
www.medford.k12.or.us/sample/imageswitcher/left.htm
and it only works when you click the plus sign on schools and the plus sign on 549C. but it doesn't switch back, and it doesn't change on any of the other Menu Items. I know the loop is structured correctly, because every other function i'm calling works correctly.
Thanks in advance
Sam

gil davis
07-21-2003, 05:29 PM
onclick="'+(clicked ? clicked=false:clicked=true)+';'+(clicked ? itemID+'img.src='up.gif'' : itemID+'img.src='down.gif'')+'"
Sorry, but that code makes no sense to me. What do you think it should do? It would appear that you have some mismatched single quotes.
onclick = "' + (clicked ? clicked=false : clicked=true) + ';' + (clicked ? itemID + 'img.src='up.gif'' : itemID+'img.src='down.gif'')+'"

sumyounguy
07-21-2003, 05:36 PM
This is from the middle of a string that i set to append to the HTML later in the jscript.

str +='...'+'onclick="'+(clicked ? clicked=false:clicked=true)+';'+(clicked ? itemID+'img.src='up.gif'' : itemID+'img.src='down.gif'')+'">';

The point is if the boolean clicked is false, make it true, and vica-versa as well as after making that switch, switch the imgs src to down.gif if clicked was changed to false and up.gif if clicked was changed to true

Hope this helps.
Thanks

gil davis
07-21-2003, 08:28 PM
You still have quotes trauma. If you split up the statement instead of trying to write a one-line wonder, it would be easier to see it.
str += '...';
str += 'onclick="';
str += (clicked ? 'clicked=false' : 'clicked=true');
str += ';';
str += (clicked ? itemID + "img.src='up.gif'" : itemID + "img.src='down.gif'");
str += '">';
Then if you want to deflate it:
str += '...' + 'onclick="' + (clicked ? 'clicked=false' : 'clicked=true') + ';' + (clicked ? itemID + "img.src='up.gif'" : itemID + "img.src='down.gif'") + '">';

sumyounguy
07-22-2003, 09:09 AM
Yeah, but my quotes aren't the problem, i've tripple checked as long as the 'up.gif' and 'down.gif' have their single quotes escaped it works somewhat right, but it only works sparatically