Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionals within jquery mobile variables

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
US
Not sure the subject explains this but I have a div I populate with results returned from an ajax call.

$('#clubsearch_list div[data-role="content"]').append(data.clublist.accountname +'<br>&nbsp;&nbsp;'+ data.clublist.accountaddy+'<BR>&nbsp;&nbsp;'+data.clublist.accountcity+'&nbsp;&nbsp;'+ data.clublist.accountzip +'<BR>&nbsp;&nbsp;'+ data.clublist.accountcontact +'<BR>&nbsp;&nbsp;<a href= "mailto:'+ data.clublist.accountemail +'" >Email</a><BR>&nbsp;&nbsp;<a href="'+ data.clublist.accounturl +'">Website</a><BR>&nbsp;&nbsp;<a href=tel:'+ data.clublist.accountphone +'>'+ data.clublist.accountphone +'</a><br>&nbsp;&nbsp;'+data.clublist.coupons+'</p><br>');

What I need to do is omit sections if there is no data. If there is no email address, I don't want it to be sent for display. I know there needs to be a if LEN(data.clublist.accountemail) = 0 {.....

Chris Scott
 
use the ternary operator

eg
Code:
[b][COLOR=#0000FF]var[/color][/b] sep [COLOR=#990000]=[/color] [COLOR=#FF0000]"<br/>&nbsp;&nbsp;"[/color][COLOR=#990000];[/color]
$[COLOR=#990000]([/color][COLOR=#FF0000]'#clubsearch_list div[data-role="content"]'[/color][COLOR=#990000]).[/color][b][COLOR=#000000]append[/color][/b][COLOR=#990000]([/color]  data[COLOR=#990000].[/color]clublist[COLOR=#990000][[/color]i[COLOR=#990000]].[/color]accountname [COLOR=#990000]+[/color] [COLOR=#990000]([/color]data[COLOR=#990000].[/color]clublist[COLOR=#990000][[/color]i[COLOR=#990000]].[/color]accountaddy[COLOR=#990000].[/color]length [COLOR=#990000]>[/color] [COLOR=#993399]0[/color] [COLOR=#990000]?[/color] sep [COLOR=#990000]+[/color] data[COLOR=#990000].[/color]clublist[COLOR=#990000][[/color]i[COLOR=#990000]].[/color]accountaddy [COLOR=#990000]:[/color][COLOR=#FF0000]''[/color][COLOR=#990000])[/color] [COLOR=#990000]);[/color]

or you could do this

Code:
[b][COLOR=#0000FF]var[/color][/b] temp [COLOR=#990000]=[/color] [COLOR=#FF0000]''[/color][COLOR=#990000];[/color]
[b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color]data[COLOR=#990000].[/color]clublist[COLOR=#990000][[/color]i[COLOR=#990000]].[/color]accountaddy[COLOR=#990000].[/color]length [COLOR=#990000]>[/color] [COLOR=#993399]0[/color][COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
  temp [COLOR=#990000]+=[/color] [COLOR=#FF0000]"<br/>&nbsp;&nbsp;"[/color][COLOR=#990000]+[/color]data[COLOR=#990000].[/color]clublist[COLOR=#990000][[/color]i[COLOR=#990000]][/color]accountaddy[COLOR=#FF0000]";[/color]
[COLOR=#FF0000]}[/color]
[COLOR=#FF0000]//...etc[/color]
[COLOR=#FF0000]$('#clubserarch_list div[data-role="[/color]content[COLOR=#FF0000]"').append ( $(temp) );[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top