bookish Posted October 15, 2018 Report Share Posted October 15, 2018 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> Quote Link to comment Share on other sites More sharing options...
Alison Posted November 27, 2018 Report Share Posted November 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
bookish Posted December 19, 2018 Author Report Share Posted December 19, 2018 Sorry for the late reply. If you could try it, please do. Please remove anything on Waitlist as we don't have waitlist anymore. Thanks much! Quote Link to comment Share on other sites More sharing options...
Alison Posted December 28, 2018 Report Share Posted December 28, 2018 Hi @bookishPlease clarify about Waitlist - which parts of the code you want to leave and which remove? Quote Link to comment Share on other sites More sharing options...
bookish Posted December 28, 2018 Author Report Share Posted December 28, 2018 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! Quote Link to comment Share on other sites More sharing options...
Alison Posted January 4, 2019 Report Share Posted January 4, 2019 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.asphttps://www.w3schools.com/jsref/met_node_appendchild.asphttps://www.w3schools.com/jsref/prop_html_innerhtml.asp Quote Link to comment Share on other sites More sharing options...
bookish Posted January 5, 2019 Author Report Share Posted January 5, 2019 Thank you @Alison for the efforts and the links. Happy new year! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.