I am trying to set up a form with an array of <select> fields which, using "onchange", JavaScript and Ajax will update a MySQL database when an item is selected. The problem I am having is that the "ID" being passed to javascript is always the last of the array:
The array is created by two nested "while" loops. The first assigns a company_id and for each company_id a second "while" loop assigns one or more "event_id"s. Each of these company/event pairs has an associated <select> field.
The <select> field is constructed like this (within a nested loop):
$prospect_array = array($company_id,$event_id,'');
$prosp = json_encode($prospect_array);
$sel_id = 'cat'.$company_id.'-'.$event_id;
// echo "Sel ID: $sel_id<br/>";
echo "<td align = 'left'>
<select name = 'category_select[$company_id,$event_id]' id='$sel_id' onchange='CategorySelected($prosp)'>
<option value = $prosp> -- </option>
";
Then, loop for each "$prosp" option:
echo "<option value= $prosp $selected> $category</option>";
As an initial test, my JavaScript, "CategorySelected", looks like this:
<script type='text/javascript'>
function CategorySelected(){
alert('Change was made');
alert($prosp);
var choice = document.getElementById('$sel_id').value;
alert(choice);
}
</script>
As mentioned, the "alerts" coming from the JavaScript show the same values for all <select> fields in the array and that value is always the very last item of the multidimensional array.
If I uncomment the "// echo 'Sel ID: $sel_id<br/>';" line, the correct values scroll up the screen.
I am sure it's a syntax error somewhere, I am just not seeing it.
Any advice would be greatly appreciated.