Explore the community Forums Lectora Lectora Questions & Answers Prevent duplicate droplist choice Reply To: Prevent duplicate droplist choice

#379716 Score: 0
Profile photo of Jason Dalrymple
Jason Dalrymple
Member
beginner
intermediate
profile
wise owl
curious george
contributor
friend finder
advanced
picture perfect
54 pts
@JasonADal

Edit: I attached a sample with my progress so far so it’s not just code to look at.

I’m hoping I can get a little more help on this one. I’m trying to create a “dual” solution” that employees the jquery that gives immediate feedback and the JS that runs onClick to highlight the duplicate and empty drop downs. So, order of operations:

  1. If the users selects a duplicate, there is an immediate alert (current jquery) and the duplicates get a red border (current JS with the onClick).
  2. When the user clicks a Submit button, the empty drop downs get a yellow border (current JS with onClick).

I’ve been able to set the button so that only the duplicates are highlighted. However, I’m stumped on how to highlight the duplicates using jquery. I’m REALLY close, though. I am able to get the “currently selected” element only to highlight, but want to try and get the duplicate highlighted, too. Here’s what I’m working with in the jquery:

$(document).ready(function () {
$(‘select’).change(function () {
if ($(‘select option[value=”‘ + $(this).val() + ‘”]:selected’).length > 1) {
var element = $(this).parent(); // this sets the variable to the currently selected drop list or blank?
alert(‘You have already selected this option previously – please choose another.’);
alert(element);
$(element).css(“border”, “solid red”); // sets the border of all items with class
}
});
});

On a side note, Tim – I’m not able to copy the button or the JS on page 1 to the other pages and get it to work. I was able to copy the jquery from page 3 to the page with the button and it does work. Any thoughts on that?

  • This reply was modified 2 years, 9 months ago by Profile photo of Jason Dalrymple Jason Dalrymple. Reason: added attachment
Attachments:
  1. Title_1.zip