Mahi
Mahi

Reputation: 73

Pass Array as a parameter in Javascript

This function is used to check if the checkbox is selected or not.Can somebody help how to pass the array as a parameter to URL which will call a stored procedure.

function js_remove_masters(theForm) {
  var vCheckedCount = 0;
  var vContinue = true;
  var mycheckedarr = [];
  var myuncheckedarr = [];
  //check to see if anything is selected
  if ((theForm.selected.length == null) && (!(theForm.selected.checked))) {
    vContinue = false;
    alert("Please select an item to be deleted.");
  } else if (theForm.selected.length != null) {
    for (var i = 0; i < theForm.selected.length; i++) {
      if (theForm.selected[i].checked) {
        vCheckedCount = 1;
        mycheckedarr.push = theForm.selected[i].value;
      } else {
        myuncheckedarr.push = theForm.selected[i].value;
      }
    }

    if (vCheckedCount == 0) {
      vContinue = false;
      alert("Please select an item to be deleted.");
    }
  }
  if (vContinue) {
    theForm.action = ("library_search_pkg_nv1.remove_checkin_masters");
    -- - here how to pass array parameters
    theForm.submit();
  }
}
procedure remove_masters(
  masterID in smallarray
  default smallempty,
  masterIDunselected in smallarray
  default smallempty
);

Upvotes: 0

Views: 72

Answers (1)

Quentin
Quentin

Reputation: 944545

Just get rid of the JavaScript entirely. You are submitting the form.

If a checkbox is checked then its name/value pair will be included in the form data.

If it isn't checked, then it won't be.

If you have a bunch of checkboxes (or other elements) with the same name, then most server side form data parsing libraries will express that as an array automatically. The main exception is PHP which requires that you put [] on the end of the name first.

Upvotes: 3

Related Questions