Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 93032

Code only works if I add Extra character

$
0
0

Hi, so there's a bit of code I use to keep a running list of pages I need to print (puts it in a textbox), solely depending on if certain boxes are checked... Say I have 3 checkboxs, and each represents a certain page or pages to be printed...  If select each of those checkboxes, pagesToPrint (a textbox) will be populated with 9-11, 15-40, 43 of the PDF (I made up the page numbers).  If I unselect one of those checkboxes, I need the value to be removed from pagesToPrint.  So pagesToPrint should read something like 9-11, 15-40.

 

The code I'm posting below WORKS, except that I have an issue having the text to remove itself from pagesToPrint when the input is just a single number AND when it's the first item in the box... Example: "43" won't remove from pagesToPrint when I unselect the textbox txt1; but if I changed it to "43 " (added space at the end), "43-44" or "43a" all would work.  So if the box read 43, 9-11, 15-40 (the integer only being first) then the 43 wouldn't remove if the corresponding checkbox were unselected.... If it were populated with 9-11, 15-40, 43 (the range being first) then the 43 would remove if the corresponding checkbox were unselected

 

Why is that??

 

// script start - Trying to debug a removal issue on txt1 when integer lacks a space, symbol, or letter

 

//get the button

var btn = this.getField("txt1");

//app.alert("value = "+btn.value);

 

 

// this variable would change for each check box to the pages you want printed.

var pagesToPrint = "43";

 

 

//check value of checkbox

if(btn.value=="Yes") {

  var action = "add";

}

else

{

  var action = "";

}

 

updatepagesToPrint(pagesToPrint, action);

 

 

function updatepagesToPrint(pagesToPrint, action) {

  //app.alert(pagesToPrint + " :: " + action);

 

  // get the text field

  var printField = this.getField("pagesToPrint");

 

  if(action=="add")

  {

  // check if the field is empty

  if ( printField.value == "" || printField.value == " ")

  {

      printField.value = pagesToPrint;

  }

  else

  {

      // as printField has a value, add the new pages to the end of the value

      printField.value = printField.value + ", " + pagesToPrint;

  }

  }

  else

  {

  printField.value = printField.value.replace(pagesToPrint+", ", "");

  printField.value = printField.value.replace(pagesToPrint, "");

  printField.value = printField.value.replace(/^,|^, |, $|,$/, "");

  }

 

 

}

 

 

// script end


Viewing all articles
Browse latest Browse all 93032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>