Jump to content

Alert Box For When Specific Value is Chosen


Recommended Posts

Is there a caspio standard way to have an alert box pop up? I have a text field value that has 6 choices, represented by radio buttons. If the user clicks on '6', I am trying to get an alert to pop up. This will just be like a dialog/alert box where the user has to click okay to get back to the form.

Can anyone help me out with this?

I have tried with some JS, however I am not sure how to implement/call it. 

var reasonChoice = [@Reason];

if (reasonChoice = "6") {
  window.alert("Please see update below.")
}

Any help is appreciated.

Link to comment
Share on other sites

Hello @kpcollier

You can use this code:

<script type="text/javascript">

document.addEventListener('DataPageReady', assignAdditionalListeners)

function assignAdditionalListeners() {
 document.querySelector('input[id^="InsertRecordtext_f0"]').addEventListener('change', customAlert); // change ID
 document.querySelector('input[id^="InsertRecordtext_f1"]').addEventListener('change', customAlert); // change ID
 document.querySelector('input[id^="InsertRecordtext_f2"]').addEventListener('change', customAlert); // change ID
 document.querySelector('input[id^="InsertRecordtext_f3"]').addEventListener('change', customAlert); // change ID
 document.querySelector('input[id^="InsertRecordtext_f4"]').addEventListener('change', customAlert); // change ID
 document.querySelector('input[id^="InsertRecordtext_f5"]').addEventListener('change', customAlert); // change ID
 document.removeEventListener('DataPageReady', assignAdditionalListeners)
}

function customAlert(event) {
 alert(event.target.value);
}

</script>

You need to place the code in the header of the form. Do not forget to disable the HTML editor in the advanced section of the footer.

You need to change the ID according to the name of the field you use.
In the Example I have name as "InsertRecordtext_f0". If your field has name "Reason", you should name ID like this - "InsertRecordReason0".

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