Context Summary
In Canada, there are temporary SIN which begin by '9' attibuted to immigrants awaiting their very SIN.
Once they receive their new "real" SIN, we must be able to update the value based on citizen name and date of birth (this is sufficient for the very system I'm working on).
Once a new citizen is added to a contract, and her/his date of birth is input, an ajax call is made to figure out whether a matching participant matches, and suggest the possible match to the user who then confirm whether there is a real match.
Once matched, the system has to update the existing user and remove the newly added one so to avoid duplicate entries. This means that in order to change a SIN for a given participant, one has to add a new participant in a previous step, and the system reports the newly created participants and prompt the user to enter further information details such as the date of birth. When the "date-time picker" closes, an ajax is called to find this match as explained above.
However, the code selecting the new SIN number item, doesn't work as expected. Instead of targeting the found participant, it selects the first participant found, which actually is a "real" new participant.
Code Sample
The new participants are listed as follows in the Web page:
<!-- Here is the very new participant -->
<tr id="17" rel="17">
<input type="text" value="SURNAME17, GIVENNAME17">
<input type="text" id="txtSIN17" value="123456789">
</tr>
<!-- Here is the participant I'd like to get the SIN from -->
<tr id="18" rel="18">
<input type="text" value="SURNAME18, GIVENNAME18">
<input type="text" id="txtSIN18" value="487654321">
</tr>
The way the system selects the participant is:
$("input[id^=txtSIN]").val();
Which inevitably always returns the first occurence, that is, SIN: 123456789
. I'd like to obtain the other SIN: 487654321
.
However, I can't predict what will be the tr id
which shall be required from time to time, and I believe I need to rely on the first input-text in order to know this "id"
.
Before I go with my thoughts, I have to mention that I have collected the name and temporary SIN from the underlying database whilst the system asked for the match. The only way I might establish a relation is by the name and date of birth of the match found.
So far...
I thought, having the value of my matched participant in a concatenated ListBox value, to do as follows:
function PerformSINChange(changeSIN) {
if (changeSIN != 0) {
// pseudo-code, since I don't yet know how to achieve what I want in jQuery.
// So I have the confirmed match here formatted as:
// "999999999 | SURNAME18, GIVENNAME18 | 1986-09-14 | 9"
var selectedMatch = $('select[id$=lstExistingParticipant]').val();
var selectedMatchName = selectedMatch.Split("|")[1].Trim();
var inputTextIdToSelect;
$("#form1 input[type=text], select").each(function(inputText) {
if (selectedName == $(inputText).val()) {
inputTextIdToSelect = $(inputText).Id();
break;
}
});
var newSINInputText = "txtSIN" + inputTextIdToSelect;
var newSINValue = $(newSINInputText).val();
var matchedParticipant = new Object();
matchedParticipant.TemporarySIN = selectedMatch
matchedParticipant.NewSIN = newSINValue;
if (matchedParticipant.TemporarySIN != "" && matchedParticipant.TemporarySIN != null)
$.ajax({
type: 'POST'
, data: matchedParticipant
, url: p.transformURL("ajax/verify_participant.ashx");
, async: false
, cache: false
, success: function (xmlResponse) {
if (xmlResponse != "") {
$('tr[id$=' + xmlResponse + ']').unbind();
$('tr[id$=' + xmlResponse + ']').remove();
var tableRow = $('.datatable_table_part tbody tr')
var tableBody = $('.datatable_table_part tbody')
if (tableRow.length == 0)
tableBody.append('<tr><td colspan="6">' + emptyTableMsg + '</td></tr>');
}
}
});
}
}
$.fancybox.close();
}
And I'm not quite sure on how to go about it from here.
How shall I go about it from here, is my idea any good? And if so, what is the correct syntax to achieve this?
Some related findings