Conditional javascript

onclick="if(this.style.background=’#F9CF00’)this.style.background=’#ffffff
else this.style.background=’#F9CF00’;

How do I implement a conditional if else statement in the onclick?

The

is white by default, when a user clicks it, and it is white, I
want it to change to orange. And vice versa,

Thanks

onclick
="if(this.style.background=’#F9CF00’)this.style.background=’#ffffff
else this.style.background=’#F9CF00’;

How do I implement a conditional if else statement in the onclick?

The

is white by default, when a user clicks it, and it is
white, I
want it to change to orange. And vice versa,

this.style.background = (this.style.background == ‘#f9cf00’ ?
#fffff’ : ‘#f9cf00’)

That last part works like this:

(some expression yielding true of false ? return this if true : return
this if false)

onclick="this.style.background=(this.style.background == ‘#F9CF00’ ?
‘red’ : ‘#F9CF00’);

Doesn’t seem to work =(

I think there was a simple typo -

onclick=“this.style.background = (this.style.background == ‘#F9CF00’)?
#FF0000’ : ‘#F9CF00’;”

You may also want to look into attaching this behind the scenes
removing your behavior from your display completely, best practice -
but that’s just the geek in me.

On Jul 14, 10:17 pm, Justin To [email protected]

Jeff.Corcoran wrote:

I think there was a simple typo -

onclick=“this.style.background = (this.style.background == ‘#F9CF00’)?
#FF0000’ : ‘#F9CF00’;”

Not working D=

You may also want to look into attaching this behind the scenes
removing your behavior from your display completely, best practice -
but that’s just the geek in me.

On Jul 14, 10:17�pm, Justin To [email protected]

Yah, once I get it to work I’ll stick it somewhere else =)

Try this: onclick=“style.backgroundColor=(style.backgroundColor ==
‘rgb(249, 207, 0)’ ? ‘#FF0000’ : ‘#F9CF00’)”

Even when you assign a string like ‘#ffffff’ internally is converted
to ‘rgb(255, 255, 255)’

Works for me in Firefox 3.0 and Safari 3.1.2

Regards.

Jeff.Corcoran wrote:

If that is still not working - can you drop an example of the code and
an error? The above example I gave you worked for me.

Jeff, it works great in Firefox 3.0, but not in IE 7, any suggestions on
that?

Thanks!!

Also, I have

onclick =
Element.show(’<%= user.email -%>’)
=> show

How do I apply the same logic as the bg color to say, "

is showing,
so onlcick hide it, and vice versa":

Element.hide(’<%= user.email -%>

Thanks!!

If that is still not working - can you drop an example of the code and
an error? The above example I gave you worked for me.

If you can give me an example of the HTML that is coming out I may be
able to help you better.

On Jul 15, 10:53 am, Justin To [email protected]

Jeff.Corcoran wrote:

If you can give me an example of the HTML that is coming out I may be
able to help you better.

On Jul 15, 10:53�am, Justin To [email protected]

How do I get that?

But there is no source for that since it’s using ajax w/o refreshing the
page. It shows the table, but the source does not reflect the contents

Use firefox. Select the generated html and right click. There is an
option
for “Show Selection Source”
Or, you can get firebug and either inspect the element or see what the
ajax
request returned

On Tue, Jul 15, 2008 at 4:47 PM, Justin To
[email protected]

Element.show(’<%= user.email -%>’) means that user.email is the id of
the tr you want to hide, right? Like this:

....

(which fails btw. if two users on that page have the same email)

Use toggle:
Show/hide it!</
span>

Of course you can’t put that into the tr itself because there’s no
clicking on something invisible.

On Jul 15, 4:53 pm, Justin To [email protected]

Justin To wrote:

How do I get that?

Just look at the source and then cut and paste

Oops, forgot the quotes

Show/hide it!</
span>

[email protected] wrote:

Oops, forgot the quotes

� Show/hide it!</
span>

Exactly what I was looking for…works like a charm!!

Thanks so much!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs