Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Check if a link is clicked

I have a link inside a div on a "Text / HTML Filler" page that respondents need to click on before continuing the survey.  Here is the code below:

<div id="accountLink">
    <a href="#" class="accountButton" target="_blank">Create an account!</a>

I'd like to show a JavaScript error message if the respondent tries to hit the submit button before clicking on the link.  What is the best way to do this?

I'm using SSI Web 8.4.8.  Thanks in advance!
asked Aug 21, 2019 by Quentin Bronze (630 points)

1 Answer

+1 vote
Best answer
Try adding HTML / JS like this beneath your code:

<input type="hidden" id="myAnchorClicked" value=""/>

$(document).on('click', '#accountLink > a', function(){

Then this custom JavaScript verification:

if (!$('#myAnchorClicked').val()) {
    strErrorMessage = 'Error message here.';
answered Aug 21, 2019 by Zachary Platinum Sawtooth Software, Inc. (216,575 points)
selected Aug 21, 2019 by Quentin
Thanks Zachary, this is exactly what I was looking for!
Check if link on terminate page is clicked
Write to a pass-in field if a link is clicked