Jump to content

Javascript Condition/show message


Recommended Posts

Looking to summarise a report data page where the result of 6 fields are summarised into 1 HTML block.

In most cases only 1 of the fields will have value but it will be possible for there to be 2 fields with value.

The following script appears to work however it has 2 issues

1. The HTML block only appears to activate with a result on  the  first result when there are multiple results

2. If 2 fields have value only one is displayed

Can anyone assist

Code is as follows

<p id="Category"></p>

<script>
if("[@field:Retail^]" == "Yes"){
document.getElementById("Category").innerHTML = "Retailer";
}
if("[@field:Farmer^]" == "Yes"){
document.getElementById("Category").innerHTML = "Farmer";
}
if("[@field:Manufacturer^]" == "Yes"){
document.getElementById("Category").innerHTML = "Manufacturer";
}
if("[@field:Distributor^]" == "Yes"){
document.getElementById("Category").innerHTML = "Distributor";
}
if("[@field:MediaBlogger^]" == "Yes"){
document.getElementById("Category").innerHTML = "Media Blogger";
}
if("[@field:Organisation^]" == "Yes"){
document.getElementById("Category").innerHTML = "Organisation";
}
</script>

Link to comment
Share on other sites

Hello @PeterOConnor,

 

Firstly, I would like to suggest to utilize the DataType of List - String. It would be much easier to do that.

However, if you wouldn't want do that due to  other dependencies, let's do some custom coding.

 

Assuming this is a Details DataPage / Drilldown, you'd just need to replace '=' to '+=' after each 'innerHTML'

In your case:

...

document.getElementById("Category").innerHTML += "Retailer";

...

document.getElementById("Category").innerHTML += "Farmer";

...

And so on.

 

You may want to see and inspect this DataPage I have created.

 

Do note that I assumed that this is a Details Drilldown. If this is not the case (if you are referring to the Table, Gallery, or List), then we should not be using `<p id="Category"></p>`, at all, as a placeholder.

Please let me know if this works.

I hope this helps.

 

D.N.31337

Link to comment
Share on other sites

It is a tabular report  result page

The script works to an extent however for multiple results it is putting all the results in the first result - refer to window snip

I would like to be able to get it to work (even for other uses) but I do have another option here I can proceed with - Application still in development mode so I am going to change the fields from yes/No to text name - then my html code is just putting the content of each field in the HTML

Thanks

Peter

Screensnip.PNG

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...