I have a table where I display some information for a user to “approve” or “deny” certain projects. I created two images: a cross sign for denials, and a check sign for approvals. On each click, I am adding the unique id to its respective hidden form field (rejectedProjs and approvedProjs). In addition, if a user clicked on “deny” then I am displaying a text box so that they can enter a reason. This is what I have so far:
$("a[name^=reject-]").each(function() {
var name = $(this).attr('name');
var p_project_number = name.split('-')[1];
$("a[name=reject-"+p_project_number+"]").tipbox("Reject pricing for "+p_project_number, 0, "reject-"+p_project_number);
$(this).click(function() {
$("textarea[name=rejReason-"+p_project_number+"]").show();
rP = $("#rejectedProjs").val();
$("#rejectedProjs").val(rP+','+p_project_number);
alert('rejects: '+$("#rejectedProjs").val());
});
});
There are two problems. First, if I click on the deny button twice for the same project, the alert box will display the project number twice. How can I check the $(“#rejectedProjs”).val() to see if that project number is already there? Second, if say I deny first and then approve, I need to remove that project from $(“#rejectedProjs”).val(). Not sure how to do this. thanks in advance.
I’d use an array instead of a hidden input. This way you can easily search through the array for already existing values, add new values, and remove values. Then, after the manipulation is complete set the value of a hidden input to the array using
array.join()A very simple example will look something like this:
and dont forget to actually include the hidden inputs in your page: