/    Sign up×
Community /Pin to ProfileBookmark

onClick value setting problem

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
[url]www.medford.k12.or.us/sample/imageswitcher/left.htm[/url]
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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJul 21.2003 — [b]onclick="'+(clicked ? clicked=false:clicked=true)+';'+(clicked ? itemID+'img.src='up.gif'' : itemID+'img.src='down.gif'')+'" [/b][/quote]
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 = "[color=red]'[/color] + (clicked ? clicked=false : clicked=true) + [color=red]'[/color];[color=blue]'[/color] + (clicked ? itemID + [color=blue]'[/color]img.src=[color=green]'[/color]up.gif[color=green]'[/color][color=orange]'[/color] : itemID+[color=orange]'[/color]img.src=[color=red]'[/color]down.gif[color=red]'[/color][color=blue]'[/color])+[color=blue]'[/color]"
Copy linkTweet thisAlerts:
@sumyounguyauthorJul 21.2003 — This is from the middle of a string that i set to append to the HTML later in the jscript.
<i>
</i>str +='...'+'onclick="'+(clicked ? clicked=false:clicked=true)+';'+(clicked ? itemID+'img.src='up.gif'' : itemID+'img.src='down.gif'')+'"&gt;';

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
Copy linkTweet thisAlerts:
@gil_davisJul 22.2003 — 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 += '"&gt;';

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'") + '"&gt;';
Copy linkTweet thisAlerts:
@sumyounguyauthorJul 22.2003 — 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
×

Success!

Help @sumyounguy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...