Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - PDF: Why does text field start with a blank line?
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

PDF: Why does text field start with a blank line?

 Post Reply Post Reply
Author
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Topic: PDF: Why does text field start with a blank line?
    Posted: 01 Sep 2018 at 9:13pm
BTW, Thanks again. I used your code and it works great!
Back to Top
Sponsored Links


Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 2018 at 9:03pm
Originally posted by BAlheit BAlheit wrote:

You can use this:
var combinedText1;
if (oldText1 == "") combinedText1  = newURL1;
else combinedText1 = oldText1 + "\n" + newURL1;

Thanks very much! I was pretty sure someone was going to suggest something like that (I know I would if I were reading this clunky code from the outside). Smile

Right now I'm a little rusty on my javascript (especially for PDFs – the bulk of my experience is in javascript for the web), so I like to write everything out in full the first time I create the code. This makes it easier for me to see/fix errors. After I know it's working, then I go back and streamline everything.

UNNECESSARY BACKGROUND:
I do this because, years ago, I spent a full day trying to track down an error in a long, complex if/else function and it wasn't until I broke each and every piece into a separate "if-test" that I discovered I had been looking for the error in the wrong place. Since then, my first pass at the code is purposefully clunky so I can test it at each-and-every step of the way. 

Thanks again!
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1107
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 2018 at 7:27am
You can use this:

var combinedText1;
if (oldText1 == "") combinedText1  = newURL1;
else combinedText1 = oldText1 + "\n" + newURL1;
Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 2018 at 6:29pm
THANKS!
I think my first attempt at checking for an empty string didn't work, so I gave up on that route. Then it came down to me doing things in the wrong order.

I have updated my code (new additions in red):

//  Summary: User will enter a URL into the textbox
//  User will click a button and the URL will be moved down
//  to the big text area. If there is already text there,
//  the new URL will be appended to the end of the list.
//
//  NOTE: I will worry about formatting the link after I
//  get this first part working.

//  ----- Elements we are working with -----
//  btn01_Mkt_addURL Button that triggers this function
//  txt01_Mkt_url Textbox (small, on top)
//  btn01_Mkt_desc Button -- IGNORE FOR NOW
//  txt01_Mkt_desc Textbox -- IGNORE FOR NOW
//  btn01_Mkt_showDesc Button shows btn01_Mkt_desc & txt01_Mkt_desc -- IGNORE FOR NOW
//  btn01_Mkt_hideDesc Button hides btn01_Mkt_desc & txt01_Mkt_desc -- IGNORE FOR NOW
//  btn01_Mkt_popup IGNORE FOR NOW
//  txt01_Mkt_combinedText   Big text area at the bottom (supports RTF content)
// =====================================================================================
//  Declare variables
var oldText1;
var newURL1;

// Get value from the first (smaller) field
newURL1 = getField("txt01_Mkt_url").value;
// Get value from the second (bigger) field at the bottom
oldText1 = getField("txt01_Mkt_combinedText").value;

//  If this is not the first entry (in other words, oldText1
//  is not empty), this adds a new line before inserting the new URL
if (oldText1 != "") {
oldText1 = oldText1 + "\n";
}
if (oldText1 == "") {
oldText1 = "";
}


// Append the two together
var combinedText1 = oldText1 + newURL1;

// Put the combined text into big text area
getField("txt01_Mkt_combinedText").value = combinedText1;


// Debugger
// app.alert("Debugger\nnewURL1 = " + newURL1 + "\n\n" + "oldText1 = " + oldText1 + "\n\n" + "combinedText1 = " + combinedText1, 3);

Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 2018 at 6:08pm
Thanks. I originally had some error trapping to handle this, but cut it out because it didn't seem to help. Maybe there was something wrong with that code. I'll go back and check.
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1107
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 2018 at 6:52am
oldText1 is an empty string.

The command "oldText1 + "\n" + newURL1" adds a newline to the empty string. The result is a blank line.
Back to Top
mmitchell_houston View Drop Down
New Member
New Member
Avatar

Joined: 29 Aug 2018
Location: Houston, TX
Points: 10
Post Options Post Options   Quote mmitchell_houston Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2018 at 9:08pm
I have created a PDF form designed to help people enter URLs into a long list.
When the user enters a new URL, it will be appended to the bottom of the list.

I've got it working (stripped out the URL functionality for testing), but it keeps adding a blank line to the beginning of the list. I've tried all sorts of things, including an if statement searching for null value, and I think there's a null in the field, but that darned line break at the start of the list is very annoying.


================================
Here's the code only if you're interested (I added comments to help you guys sort out what I'm up to).

//  Summary: User will enter a URL into the textbox
//  User will click a button and the URL will be moved down
//  to the big text area. If there is already text there,
//  the new URL will be appended to the end of the list.
//
//  NOTE: I will worry about formatting the link after I
//  get this first part working.

//  ----- Elements we are working with -----
//  btn01_Mkt_addURL Button that triggers this function
//  txt01_Mkt_url Textbox (small, on top)
//  btn01_Mkt_desc Button -- IGNORE FOR NOW
//  txt01_Mkt_desc Textbox -- IGNORE FOR NOW
//  btn01_Mkt_showDesc Button shows btn01_Mkt_desc & txt01_Mkt_desc -- IGNORE FOR NOW
//  btn01_Mkt_hideDesc Button hides btn01_Mkt_desc & txt01_Mkt_desc -- IGNORE FOR NOW
//  btn01_Mkt_popup IGNORE FOR NOW
//  txt01_Mkt_combinedText   Big text area at the bottom (supports RTF content)
// =====================================================================================
//  Declare variables
var oldText1;
var newURL1;

// Get value from the first (smaller) field
newURL1 = getField("txt01_Mkt_url").value;
// Get value from the second (bigger) field at the bottom
oldText1 = getField("txt01_Mkt_combinedText").value;


// Append the two together
var combinedText1 = oldText1 + "\n" + newURL1;

// Put the combined text into big text area
getField("txt01_Mkt_combinedText").value = combinedText1;

// Debugger
app.alert("Debugger\nnewURL1 = " + newURL1 + "\n\n" + "oldText1 = " + oldText1 + "\n\n" + "combinedText1 = " + combinedText1, 3);

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.