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>
</div>


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 Q (270 points)

1 Answer

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

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

<script>
$(document).on('click', '#accountLink > a', function(){
    $('#myAnchorClicked').val(1);
})
</script>


Then this custom JavaScript verification:

if (!$('#myAnchorClicked').val()) {
    strErrorMessage = 'Error message here.';
}
answered Aug 21, 2019 by Zachary Platinum Sawtooth Software, Inc. (134,850 points)
selected Aug 21, 2019 by Q
Thanks Zachary, this is exactly what I was looking for!
...