Expand my Community achievements bar.

Trying to keep field blank using JavaScript.

Avatar

Level 2
I have put this script in to the totals field which works fine but displays $0.00.



form1.costs.spetot.rawValue = form1.costs.spei1.rawValue + form1.costs.spei2.rawValue;



To try and remove this Ive used a script out of the Extending Acrobat Forms with JavaScript. Ive also read that the get,Field needs to be changed in Designer but I can not seem to see where Im going wrong.



The setup is:



3 fields



First is special item1 = spei1

Second is special item 2 = spei2

This is the total = spetot



Just want a script that will add the 2 fields spei1 and spei2 but not show a figure is spetot until a figure is keyed in.



var myDoc = event.target;

var sb1 = myDoc.getField("form1[0].costs[0].spei1[0]");

var sb2 = myDoc.getField("form1[0].costs[0].spei2[0]");



if (spetot.rawValue != 0)

event.value = sb1.value + sb2.value

else

event.value = ""



Error message:

SyntaxError: unterminated regular expression literal

1:XFA:form1[0]:costs[0]:spetot[0]:calculate



Can someone please help me?



Regards, John.
2 Replies

Avatar

Former Community Member
John_Kordas@adobeforums.com wrote:

> I have put this script in to the totals field which works fine but displays $0.00.

>

> form1.costs.spetot.rawValue = form1.costs.spei1.rawValue + form1.costs.spei2.rawValue;

>



Try this instead:



var totalval = form1.costs.spei1.rawValue + form1.costs.spei2.rawValue;

if (totalval == 0 || totalval == null || totalval == "")

{

this.rawValue = "";

}

else

{

this.rawValue = totalval;

}





Hope this helps!



Justin Klei

Cardinal Solutions Group

www.cardinalsolutions.com





PS - You'll get much better responses to these types of questions in the Designer forum rather than

this one.

Avatar

Level 2
Thank you Justin,



I am immensely great full and for your help it worked like a treat. I have posted a couple of questions in the Designer section but did not get any response. Not sure if its the why I put my questions out , so I thought Id try here.



Ive created some basic forms using the FormCalc language but never tried JavaScript. Ive spent the last 2 weeks watching JavaScript DVDs which are more based on WEB design. I also purchased John Deuberts book Extending Acrobat Forms with JavaScript which was fantastic, until you try some of the scripts in Designer. Ive also downloaded all the reference files and examples off the Adobe site.



This was my last hope if no one responded to this post I was going to give it away. So you can understand why I am so grateful.



Thanks Justin 