Jump to content

From if-then to CASE-when


Recommended Posts

HI! Could anyone help me transform this code to a CASE-when scenario?

<script>
if ([@field:amount] == "0")
   {
      document.write("No Signup Yet");
    }
else if([@field:attendees] < [@field:max_attendees])
   {
      document.write("<a href='URL?ID=[@authfield:ID]&activity=[@field:activity]&amount=[@field:amount]'>Signup Here</a>");
    }
else if ([@field:waitlisted] < [@field:max_waitlist])
   {
      var test='Closed. <a href="URL?ID=[@authfield:ID]&activity=[@field:activity]&amount=';
      var countr = '[@field:country]';
      if ((countr !="country1")&&(countr !="country2"))
         {
            if('[@field:activity]'=="activity1")
               {
                  test=test+'[@field:amount1]';
               }
            else
               {
                  if('[@field:activity]'=="activity2")
                     {
                        test=test+'[@field:amount2]';
                     }
                  else
                     {
                        test=test+'[@field:amount]';
                     }
                }
         }
      else
         {
            test=test+'[@field:amount]';
         }
      test=test+'">Waitlist me</a>';
      document.write(test);
   }
else
   {
      document.write("<div>Signup & Waitlist Closed</div>")
   }
</script>
Link to comment
Share on other sites

  • 1 month later...

 

Hi @bookish,

Unfortunately, this code cannot be fully transformed into the Case-When scenario since HTML elements, for example, links, are rendered as a plain text. This code can be transformed into the Case-When scenario only partially and with the additional JavaScipt code.  If you would like to, I could try to create it for you.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

HI Alison,

The results should only be NO SIGNUP YET, SIGNUP HERE and SIGNUP CLOSED.

Hence: please remove  any reference to waitlist like:

a. here in else if([@field:attendees] < [@field:max_attendees])

b. or here in test=test+'">Waitlist me</a>';

c. the last part should just say  document.write("<div>Signup Closed</div>"), removing "& Waitlist "

Thanks!

Link to comment
Share on other sites

Hi @bookish,

Unfortunately, it cannot be transformed into the Case When statements due to the fact that there still will be a lot of JavaScripts inputs. If you want to make inputs to the datapage without rewriting the whole HTML page, like the document.write method does, I can suggest that you replace the document.write  with the appendChild or innerHTML.

Please follow these link for more information:
https://www.w3schools.com/jsref/met_doc_write.asp
https://www.w3schools.com/jsref/met_node_appendchild.asp
https://www.w3schools.com/jsref/prop_html_innerhtml.asp

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...