I have a script that produces id's that look like array elements as follows:
<select name="serviceTypeID[1]" id="serviceTypeID[1]" ...
<select name="serviceTypeID[2]" id="serviceTypeID[2]" ...
<select name="serviceTypeID[3]" id="serviceTypeID[3]" ...
<select name="serviceTypeID[4]" id="serviceTypeID[4]" ...
and so on up to 10 currently...
How can I code my jquery script to reference them? This code does not work.
$('#serviceTypeID[1],#serviceTypeID[2],#serviceTypeID[3],#serviceTypeID[4]').change(function() {
var first = parseInt( $('#firstService[1]').val() );
var second = parseInt( $('#secondService[1]').val() );
var third = parseInt( $('#thirdService[1]').val() );
if (isNaN(first)) first = 0;
if (isNaN(second)) second = 0;
if (isNaN(third)) third = 0;
$('#serviceTotal[1]').val( ( first + second + third + ' Total') );
first = parseInt( $('#firstService[2]').val() );
second = parseInt( $('#secondService[2]').val() );
third = parseInt( $('#thirdService[2]').val() );
if (isNaN(first)) first = 0;
if (isNaN(second)) second = 0;
if (isNaN(third)) third = 0;
$('#serviceTotal[2]').val( ( first + second + third + ' Total') );
first = parseInt( $('#firstService[3]').val() );
second = parseInt( $('#secondService[3]').val() );
third = parseInt( $('#thirdService[3]').val() );
if (isNaN(first)) first = 0;
if (isNaN(second)) second = 0;
if (isNaN(third)) third = 0;
$('#serviceTotal[3]').val( ( first + second + third + ' Total') );
first = parseInt( $('#firstService[4]').val() );
second = parseInt( $('#secondService[4]').val() );
third = parseInt( $('#thirdService[4]').val() );
if (isNaN(first)) first = 0;
if (isNaN(second)) second = 0;
if (isNaN(third)) third = 0;
$('#serviceTotal[4]').val( ( first + second + third + ' Total') );
//and so on up to 10 currently
});
Nothing is returning from the jquery script so I feel that I am referencing it wrong in my jquery. Thanks