I have two javascript functions, insertAddedSup and removeAdded. When I retrieve values from a table and populate a control with this information, the onclick event inserts the user and the “Remove” button works fine. When I use LDAP to search for a user, and I click on the user, all of the html is correct (shows the correct parameters being sent to the remove function – just like the SQL result), but when I click on the remove button, the value of the parameter being used in the function is different from that which shows up in the html. I don’t recognize the value from anywhere… it seems almost random, though it is always the same value. Not sure what to do. Does anyone know what might be the problem?
Here are the functions:
function insertAddedSup(uidSup, fullnameSup) {
var fullnameSup = fullnameSup.toLowerCase();
var currentContentSup = '<div id="y_' + uidSup + '" class="selectedDataBox" style="overflow:hidden;"><span style="text-transform:capitalize; float:left">' + fullnameSup + '</span><input type="hidden" name="EmpID" id="personAddedSup_' + uidSup + '" value="' + uidSup + '"><input type="button" name="removeAdded_' + uidSup + '" id="removeAdded_' + uidSup + '" value="Remove" onclick="alert(' + uidSup +');removeAdded(' + uidSup + ');" style="font-size:0.7em; float:right; width:60px;"></div>';
$('#addedPerson').html(currentContentSup);
alert($('#addedPerson').html());
$('#addedPerson').show();
$('#MainContent_searchContent_btnSubmitEmployee').attr('disabled', false);
}
function removeAdded(uidSup) { // hide the div of the person added
var divID = "#y_" + uidSup;
alert($('#addedPerson').html());
$(divID).hide();
$(divID).remove();
if ($('#addedPeople').html() == '') {
$('#addedPeople').hide();
}
$('#MainContent_searchContent_btnSubmitEmployee').attr('disabled', true);
}
I added some alerts so that I can see what is actually being sent, what is in the html, etc.
Edit: HTML
<div id="y_0730337" class="selectedDataBox" style="overflow:hidden;">
<span style="text-transform:capitalize; float:left"></span>
<input name="EmpID" id="personAddedSup_0730337" value="0730337" type="hidden">
<input name="removeAdded_0730337" id="removeAdded_0730337" value="Remove" onclick="alert(0730337);removeAdded(0730337);" style="font-size:0.7em; float:right; width:60px;" type="button">
</div>
It also seems to work ok if the number does not start with a 0. Is there some way that I can make sure that the value is treated as a string?
In your button onclick:
These are being treated as numbers and not strings because you don’t have quotation marks around the parameters. If a number begins with a 0 the number will really begin with the next non zero number (in this case 7) making the value passed 730337 (I honestly don’t know why what you see as the actual value passed is so vastly different though. I’d be interested in hearing if someone else had an explanation for this).
What you really want is:
You saying numbers that don’t begin with a 0 work make me believe that this is why you are having this problem.