Good morning. I am slowly but surely figuring out jQuery, but this morning I find myself stumped and head-scratching. First, my relevant code:
HTML
<fieldset class="fieldset2">
<legend>Return Specific Curriculum Information</legend>
<input type="hidden" id="ccnt" value="0">
<table class="table" id="retc">
<thead>
<tr>
<th class="th">#</th>
<th class="th">Year</th>
<th class="th">Lang</th>
<th class="th">Week/Packet</th>
<th class="th">Quantity</th>
<th class="th">Delete</th>
</tr>
</thead>
<tbody></tbody>
</table>
<input type="button" value="Add Curriculum To Return" class="button" id="addcurric">
<input type="button" value="Remove All Entries" class="button" id="remcurric">
</fieldset>
JavaScript/jQuery
$('#ccnt').data('count', 0);
$('#addcurric').click(function () {
function getcount() {
var $this = $('#ccnt'),
count = $this.data('count') + 1;
$this.data('count', count);
return count;
}
var mycount = getcount();
var myyear = 'cyear' + mycount;
var mylang = 'clang' + mycount;
var myweek = 'cweek' + mycount;
var myqty = 'cqty' + mycount;
alert('mycount: ' + mycount + '; myyear: ' + myyear + '; mylang: ' + mylang + '; myweek: ' + myweek + '; myqty: ' + myqty);
var tdclass;
if (mycount % 2 == 1) {
tdclass = "td1";
} else {
tdclass = "td2";
}
var chtml = "";
chtml += "'<tr>";
chtml += " <td class=\"" + tdclass + "\">" + mycount + "</td>\n";
chtml += " <td class=\"" + tdclass + "\"><select name=\"" + myyear + "\" id=\"" + myyear + "\">\n";
chtml += " <option value=\"0\">-- Select --</option>\n";
chtml += " <option value=\"1\">Year 1</option>\n";
chtml += " <option value=\"2\">Year 2</option>\n";
chtml += " <option value=\"3\">Year 3</option>\n";
chtml += " </select></td>\\n";
chtml += " <td class=\"" + tdclass + "\"><select name=\"" + mylang + "\" id=\"" + mylang + "\">\n";
chtml += " <option value=\"0\">-- Select --</option>\n";
chtml += " <option value=\"1\">English</option>\n";
chtml += " <option value=\"2\">Spanish</option>\n";
chtml += " </select></td>\\n";
chtml += " <td class=\"" + tdclass + "\"><select name=\"" + myweek + "\" id=\"" + myweek + "\">\n";
chtml += "";
chtml += " </select></td>\n";
chtml += " <td class=\"" + tdclass + "\"><input type=\"text\" name=\"" + myqty + "\" class=\"input\"></td>\n";
chtml += " <td class=\"" + tdclass + "\"><button type=\"button\" class=\"dbutton\" title=\"Remove This Row\">X</button></td>\n";
chtml += " </tr>\n'";
$('#retc > tbody').append(chtml);
$(".dbutton").bind("click", Delete);
});
$('#remcurric').click(function () {
$('#retc > tbody').html("");
$('#ccnt').data('count', 0);
});
function Delete() {
var par = $(this).parent().parent();
par.remove();
}
The Problem/Question
As you can see, in my js/jQ code, I am generating dynamic table rows to handle 1-n records. I also left a blank where option lines should be for id "myweek" - because they should come from my database. Ordinarily, I would do something like this to fill those in:
$('#'+mylang).change(function() {
var lang = $('#'+mylang).val();
var year = $('#'+myyear).val();
$.post("/chairs-dev/jqf/returncurric_processajax.php", {LANG: lang, YEAR: year}, function (data) {
$('#'+myweek).append(data);
});
});
This code didn't work, so I went code hunting online. I have tried about every permutation I can think of or find online to solve this issue, but none of it works. I am sure there is something basic I'm missing here, but I just can't see it. Any thoughts on how I can get this to work?
Thanks in advance!!
EDIT: Sorry, jsfiddle link