• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

ternary operator not working to "toggle" a value


I'd like to toggle the value of my edit button from Edit to Cancel and vs. I can't use the toggle method, because I have other stuff happening on click (ommited here).

It goes from Edit to Cancel, but never back to Edit. The initial value of .edit is "Edit".

$(".edit").live("click", function(){
                    
                    var edit = $(this).val("Edit");
                    var cancel = $(this).val("Cancel");
                    
                    edit ? cancel : edit;

                    // other code

});

Open in new window

0
Kyle Hamilton
Asked:
Kyle Hamilton
  • 6
  • 2
1 Solution
 
twohawksCommented:
does that need to be (on line 6)
this.edit ? ....etc...
0
 
twohawksCommented:
Wait a minute...
that line says
if edit is true... so isn't it going to be true whether its cancel or edit, i.e., "set" either way, or is being set to cancel mean not true in this context?
0
 
Kyle HamiltonData ScientistAuthor Commented:
this.edit ? this.cancel : this.edit;

and

$(this).edit ? $(this).cancel : $(this).edit;

is all saying the same thing. And no, no love...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Kyle HamiltonData ScientistAuthor Commented:
Yes, you're right. I'm getting mixed up.

Still, I've tried a bunch of variations, and I can't seem to get my brain around the thing...

Any ideas?
0
 
Kyle HamiltonData ScientistAuthor Commented:
OK, I got it, if any one is interested...



$(this).val() == "Edit" ? $(this).val("Cancel") : $(this).val("Edit");

Thanks for the effort...
Cheers
0
 
Kyle HamiltonData ScientistAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 250 points for twohawks's comment http:/Q_27387262.html#36937487
Assisted answer: 0 points for kozaiwaniec's comment http:/Q_27387262.html#36937543

for the following reason:

Thanks for pointing me in the right direction.
0
 
Kyle HamiltonData ScientistAuthor Commented:
I awarded the "Solution" to the wrong comment. I want to re-award the points, but mark the correct comment as the solution.
0
 
Kyle HamiltonData ScientistAuthor Commented:
How am I supposed to award "Assisted solution" to my colleague?

Ughhh... this is taking longer than fixing my issue....
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now