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