Author Topic: Showing/Not showing Field Data With IF and Else  (Read 13353 times)

0 Members and 1 Guest are viewing this topic.

Offline ADalby

  • Moderator
  • Hero Member
  • *****
  • Posts: 241
    • Uniting Bands - Where Talents Unite! - Music Promotion, Musician Classifieds
Showing/Not showing Field Data With IF and Else
« on: September 17, 2007, 09:22:53 AM »
I've got 2 different fields that make up a bio section on my website. They are "name" and "bio". Note: Both fields are in seperate <table> cells so they can't go on top of each other

Here is what I'm after:

If there is a [[name]] then I need it printed out
If there is a [[bio]] then print out
If there is no [[bio]] or words then print out "Bio Coming Soon"
If there is no [[name]] present then I don't want anything printed for either field.

Here is the script that is close but I can't figure out the bio part to work with the name if it's present.

<script>
var doc1 = "[[name]]"
if (doc1 == "[[name]]") {
document.write("[[name]]")
}
else {
document.write("")
}
</script>
« Last Edit: September 17, 2007, 09:49:58 AM by ADalby »
Uniting Bands
www.unitingbands.com

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Showing/Not showing Field Data With IF and Else
« Reply #1 on: September 17, 2007, 09:51:55 AM »
Aaron,

Not too hard...  just use two scripts:

This is the name field:
<script>
var name = "[[name]]"
if (name == "[[name]]") {
document.write("[[name]]")
}
else {
document.write("")
}
</script>

This is the bio field:
<script>
var bio = "[[bio]]"
var name = "[[name]]"
if (name == "[[name]]" && bio == "[[bio]]") {
document.write("[[bio]]")
}
else if (name == "") {
document.write("")
}
</script>

Not tested but that should work.  The only this maybe holding it up in production might be the &&.  You might have to experiment there.

Jason
Founder of www.slipdex.com

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Showing/Not showing Field Data With IF and Else
« Reply #2 on: September 17, 2007, 10:23:07 AM »
Actually, change all that Aaron.....

This is the name field:
<script>
var name = "[[name]]"
if (name == "") {
document.write("")
}
else {
document.write("[[name]]")
}
</script>

This is the bio field:
<script>
var name = "[[name]]"
var bio = "[[bio]]"
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("[[bio]]")
}
else{
document.write("Coming Soon")
}
</script>

Might have to play with the != as with text sometimes this gets iffy.  can maybe try !== as well if you get errors or the nondesired result.

Jason
Founder of www.slipdex.com

Offline ADalby

  • Moderator
  • Hero Member
  • *****
  • Posts: 241
    • Uniting Bands - Where Talents Unite! - Music Promotion, Musician Classifieds
Re: Showing/Not showing Field Data With IF and Else
« Reply #3 on: September 17, 2007, 10:44:16 AM »
Thanks Jason I will give this a shot! In my bio text I will have commas and apostophies, is this going to make the script fail?
Uniting Bands
www.unitingbands.com

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Showing/Not showing Field Data With IF and Else
« Reply #4 on: September 17, 2007, 11:00:26 AM »
Apostophies shouldn't make it too bad unless there are two within the string.  I could mess around and see if I could "find and destroy" them, but since this is printing out the text string and not part of an actual function I am thinking it will get by.  Just give it a shot and if it messes up and we cross that bridge when we get to it.  The commas should cause any issues that I know of.

Jason
Founder of www.slipdex.com

Offline ADalby

  • Moderator
  • Hero Member
  • *****
  • Posts: 241
    • Uniting Bands - Where Talents Unite! - Music Promotion, Musician Classifieds
Re: Showing/Not showing Field Data With IF and Else
« Reply #5 on: September 17, 2007, 12:49:03 PM »
Hey Jason I just can't get my head around this one... I can simplify this a bit I think...

I need it to work like this:

if
[[name]] does NOT = "_.jpg"
&
[[field50]] = "Checked"

Then write "Bio Coming Soon"

Anything else has no output and is blank.


something like this maybe

<script>
var name = "_.jpg"
var bio = "Checked"
if (name == "[[name]]") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("")
}
else{
document.write("Bio Coming Soon!")
}
</script>


It must be a Monday cause I can't think straight! Must be the beers and football from yesterday! :-)
« Last Edit: September 17, 2007, 12:51:08 PM by ADalby »
Uniting Bands
www.unitingbands.com

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Showing/Not showing Field Data With IF and Else
« Reply #6 on: September 17, 2007, 01:51:09 PM »
Aaron,

My understanding of how you wanted to write the name and bio fields was that they were in seperate table cells, if that is in fact the case, you will have to use two seperate scripts.  The second set I put up there should do the trick, though now I am thrown off with the field50 equalling checked?  I am not sure where that comes from. 

If [[name]] should equal a string of text like John Smith, and [[bio]] should equal a string of text such as JM is the greatest, the my second set should work based on this premise:

This is the name field:
<script>
var name = "[[name]]"
if (name == "") {
document.write("")
}
else {
document.write("[[name]]")
}
</script>

Source output:
<script>
var name = "John Smith"
if (name == "") {
document.write("")
}
else {
document.write("John Smith")
}
</script>

This is the bio field:
<script>
var name = "[[name]]"
var bio = "[[bio]]"
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("[[bio]]")
}
else{
document.write("Coming Soon")
}
</script>

Source output:
<script>
var name = "John Smith"
var bio = "JM is the greatest"
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("JM is the greatest")
}
else{
document.write("Coming Soon")
}
</script>

So overall viewable output would be:
John Smith
JM is the greatest

If the name field is blank:
Source output finds no text string in [[name]]
<script>
var name = ""
if (name == "") {
document.write("")
}
else {
document.write("")
}
</script>

Source output finds no name relating to the bio section but does find a bio:
<script>
var name = ""
var bio = "JM is the greatest"
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("JM is the greatest")
}
else{
document.write("Coming Soon")
}
</script>

Viewable output would be nothing.

Source output finds name relating to the bio section but does find a bio:
<script>
var name = "John Smith"
var bio = ""
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("Coming soon")
}
else{
document.write("Coming Soon")
}
</script>

I didn't test it, but that should really work for what you were trying.

Jason
Founder of www.slipdex.com

Offline ADalby

  • Moderator
  • Hero Member
  • *****
  • Posts: 241
    • Uniting Bands - Where Talents Unite! - Music Promotion, Musician Classifieds
Re: Showing/Not showing Field Data With IF and Else
« Reply #7 on: September 17, 2007, 02:15:53 PM »
Yes Jason I did get this one to work! I just subbed in Field50 in place of my bio field which is checked when I have a bio filled out. Sorry for the confusion.

<script>
var name = "[[name]]"
var bio = "[[bio]]"
if (name == "") {
document.write("")
}
else if (name != "" && bio != ""){
document.write("[[bio]]")
}
else{
document.write("Coming Soon")
}
</script>
Uniting Bands
www.unitingbands.com