SO - 29113698
HTML
<iframe name="hidden_iframe" id="hidden_iframe" style="display:none;" onload="if(submitted) {breakRedirect();}"></iframe>
<form action="https://docs.google.com/forms/d/1SueoRbKQ4LVp-S5jHyjper-ZVH1W3YgnA1ySoH9nC-k/formResponse" method="POST" id="mainform" target="hidden_iframe" onsubmit="submitted=true;">
<div id="username">Username:
<input type="text" name="entry.470211283" id="entry_470211283" dir="auto" aria-label="Username " aria-required="true" required="" title="Username" value="testname" tabindex="1" class="useLocal useLocalInput">
</div>
<div id="nameselections">
<table id="maintable">
<tr>
<td>Name 1
<br>
<select name="entry.1382992313" id="entry_163533678" aria-label="1st" aria-required="true" required="" title="1" tabindex="2" class="useLocal useLocalSelect">
<option value="">-</option>
<option value="test1" selected="selected">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>
<option value="test4">test4</option>
<option value="test5">test5</option>
<option value="test6">test6</option>
<option value="test7">test7</option>
<option value="test8">test8</option>
<option value="test9">test9</option>
<option value="test10">test10</option>
</select>
</td>
<td>Name 2
<br>
<select name="entry.574800946" id="entry_574800946" aria-label="2nd" aria-required="true" required="" title="2" tabindex="3" class="useLocal useLocalSelect">
<option value="">-</option>
<option value="test1">test1</option>
<option...
CSS
.duplicate {
background-color: #ff9696;
}
JavaScript
function breakRedirect() {
var month = new Array();
month[0] = "01"; month[1] = "02"; month[2] = "03"; month[3] = "04"; month[4] = "05"; month[5] = "06"; month[6] = "07"; month[7] = "08"; month[8] = "09"; month[9] = "10"; month[10] = "11"; month[11] = "12";
var collection = new Date().getDate() + "/" + month[new Date().getMonth()] + "/" + new Date().getFullYear() + " "+ new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds();
var $inputs = $("input")
$inputs.each(function () {
var value = this.value;
if (value != "Submit Selections" && value != "Clear Selections") {
collection += "\t" + value
};
});
var $selects = $("select")
$selects.each(function () {
var value = this.value;
collection += "\t" + value
});
console.log(collection);
$('#container').replaceWith('<div id="complete">Completed</div>');
};
// Check for duplicates
function checkSelect() {
var $selects = $("select").removeClass('duplicate');
$selects.each(function () {
var value = this.value;
$selects.not(this).has('option[value="' + this.value + '"]:selected').addClass('duplicate');
})
var valid = !$selects.hasClass('duplicate');
if (!valid) {
var $div2 = $("#error").stop(true, true);
if ($div2.is(":hidden")) {
$div2.show("slow");
setTimeout(function () {
$div2.hide("slow");
}, 10000);
}
}
return valid;
};
$(function () {
$('#mainform').submit(function () {
// it's not doing anything
//checkDropdowns()
submitted = checkSelect();
return submitted;
//return true; // return false to cancel form action
});
$("select").on("change", function () {
$(this).removeClass("duplicate");
});
});