Hi Rick,

I think these explanations are correct, if not someone else should correct me :p

so, row[19] is kind of like an object and it contains the value of whatever row[19] is.
so lets say row[19] is this <div>Hello</div>

In your 'Boolean' example, this is what is happening
If row[19] exists in the dom, print 'Yes', if not print 'No'

Now in the 'non-null' example, essentially the exact same check is happening, but you have replaced Yes with the row[19] object, which contains the value of Hello, so we get this

If row[19] exists in the dom, print row[19]'s value, if not print 'N/A'

So, you can see, the second example is not checking if row[19] has a value, but whether or not it exists at all.

Now, I would take this with a pinch of salt, as my programming theory is poor at best, but this is what I think is happening.

- Liam

Rick Faircloth wrote:
Thanks, Liam...

You'll see in my answers to my own posts that I finally figured out
the extra set of quotes was needed.

What I still don't understand is even how this logic works:

if ( row[19] ) {
row[19]
} else {
N/A
}

As a "non-null" check, it seems the statement would need to be asking:

"if there is a value at row[19], use that value...otherwise us 'N/A'"

As a Boolean check, the statement would be:

if   ( row[19] == 'true' )
     { 'Yes' }
else { 'No'  }

(Assuming I wrote that correctly...)

It seems the statement would be asking:

"if the value at row[19] is 'true', use 'Yes' as the output value,
otherwise, use 'No'"

In other words, how does the conditional know what's being asked in the
shorthand version?

' + (row[19] ? '' + row[19] + '' : 'N/A') + '<

That first part:

' + row[19] ? '

works the same for both value checks and Boolean checks.

How?

Rick


-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of Liam Potter
Sent: Tuesday, August 11, 2009 11:24 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: How to specify a default value...


Your concatenation is broke, (I'm assuming the logic behind this is actually working)

this
 >' + (row[19] ? '+ row[19] + ' : 'N/A') + '<

should be
' + (row[19] ? ''+ row[19] + '' : 'N/A') + '<

As for what is going on here, it's just an if statement shortened down, and could be written like this

if ( row[19] ) {
row[19]
} else {
N/A
}

Rick Faircloth wrote:
Well..another unexpected result.

When the inline conditional:

' + (row[19] ? ' + row[19] + ' : 'N/A') + '<
is used when a **value is present** in row[19], I get this as the output:

+ row[19] +

instead of the actual value.

If I remove the quotes from ' + row[19] + ', I get a syntax error.

However, if **no value is present** in row[19], I get

N/A

as the output, which is expected.

So, the conditional is working if no value is present, but outputting the literal string

+ row[19] +

if a value is not present.

Assistance in understanding, anyone?

Thanks,

Rick

*From:* jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] *On Behalf Of *Rick Faircloth
*Sent:* Tuesday, August 11, 2009 11:00 AM
*To:* jquery-en@googlegroups.com
*Subject:* [jQuery] Re: How to specify a default value...

Well.to answer my own question.I found this works:

out.push('<li><span class="spanLeft">Pet Deposit</span><span class="spanRight">' + (row[19] ? ' + row[19] + ' : 'N/A') + '</span></li>');

But how does the conditional know whether a Boolean is being checked, as in:

' + (row[19] ? 'Yes' : 'No') + '<
Or whether the presence of a value is being checked, as in:

' + (row[19] ? ' + row[19] + ' : 'N/A') + '<
What's the logic that's occurring behind the statements to differentiate?

Thanks for any insight.

Rick

*From:* jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] *On Behalf Of *Rick Faircloth
*Sent:* Tuesday, August 11, 2009 10:39 AM
*To:* jquery-en@googlegroups.com
*Subject:* [jQuery] How to specify a default value...

I was shown how to use this inline condition for creating yes/no Boolean values instead of

the normal true/false values javascript uses:

<span class="spanRight">' + (row[20] ? 'Yes' : 'No') + '</span>

I'd like to know if there's an equivalent inline method for providing a default value

when no value is present, such as:

<span class="spanRight">' + (row[20] ? 'NORMAL ROW[20] VALUE' : 'N/A') + '</span>

Basically, if there's no value in the current row as position 20, then just us 'N/A'.

Is this possible with a simple inline condition, too?

Thanks,

Rick


----------------------------------------------------------------------------
------------------------------------------
/"Ninety percent of the politicians give the other ten percent a bad reputation." - Henry Kissinger/




Reply via email to