Yesterday or the day before I got some help with a drop down select to variable value match.
What happens is that if there is a match on the drop down, they jQuery code goes through the values and checks to see if there is a match on prices and cases. If there is a mismatch then the alert box is triggered.
The first part works fine, but the second part is more tricky and I can’t seem to figure it out.
$("select").change(function() {
var $this = $(this);
//first part
if ($("select").filter(function() {
return $(this).val() === $this.val();})
.parent()
.next()
.children("input[value!='" + $this
.parent()
.next()
.children("input")
.val() + "']")
.length != 0) {
// alert
alert('mismatch1');
}
//second part
if ($("select").filter(function() {
return $(this).val() === $this.val();})
.children("td:eq(2)::has(input[value!='" +
$this.children("td:eq(2)>input").val() + "'])").length != 0) {
// alert
alert('mismatch2');
}
});
//$this.children("td:eq(2)>input").val() <<< this works
<form name="form1" ID="form1" action="array_script.cfm">
<table id="test1">
<tr>
<td>
<select name="selectA" id="selectA" class="priceA">
<option id="A" value="">None</option>
<option id="A" value="A">A</option>
<option id="A" value="B">B</option>
<option id="A" value="C">C</option>
</select>
</td>
<td>
<input id="priceA" type="text" name="price" value="8.99">
</td>
<td>
<input id="perCaseA" type="text" name="perCase" value="4">
</td>
</tr>
<tr>
<td>
<select name="selectB" id="selectB" class="priceB">
<option id="B" value="">None</option>
<option id="B" value="A">A</option>
<option id="B" value="B">B</option>
<option id="B" value="C">C</option>
</select>
</td>
<td>
<input id="priceB" type="text" name="price" value="8.99">
</td>
<td>
<input id="perCaseB" type="text" name="perCase" value="4">
</td>
</tr>
<tr>
<td>
<select name="selectC" id="selectC" class="priceC">
<option id="C" value="">None</option>
<option id="C" value="A">A</option>
<option id="C" value="B">B</option>
<option id="C" value="C">C</option>
</select>
</td>
<td>
<input id="priceC" type="text" name="price" value="8.99">
</td>
<td>
<input id="perCaseC" type="text" name="perCase" value="4">
</td>
</tr>
</table>
</form>
Don’t know if I understood what you’re trying to do, but maybe the following code will help.
http://jsfiddle.net/cfQSr/19/
It adds the class
mismatchtotds whoseinputs don’t match, if the correspondingselecthave the same value: