Expand my Community achievements bar.

SOLVED

Help Creating a button

Avatar

Former Community Member

I am trying to create a button that when i click on it the Time shows up on the button. this is the code that i have right now and i am not sure where to go from here.

<field h="24.8811mm" name="button1" w="132.6067mm" x="34.0872mm" y="335.6257mm">

<

ui>

<

button/>

</

ui>

<

font typeface="Myriad Pro"/>

<

caption>

<

value>

<

text>button</text>

</

value>

<

para hAlign="center" vAlign="middle"/>

<

font typeface="Myriad Pro"/>

</

caption>

<

border hand="right">

<?templateDesigner StyleID apbx2?>

<

edge cap="butt" stroke="raised"/>

<

fill>

<

color value="212,208,200"/>

</

fill>

</

border>

<

bind match="none"/>

<

event activity="click">

<

script contentType="application/x-javascript">Stamp = new Date();var Hours;var Mins;var Time;Hours = Stamp.getHours();if (Hours &gt;= 12) {Time = " P.M.";}else {Time = " A.M.";}if (Hours &gt; 12) {Hours -= 12;}if (Hours == 0) {Hours = 12;}Mins = Stamp.getMinutes();if {Mins 10} {Mins = "0" + Mins;} xmlDoc.getElementById("button1").value= Hours + Mins + Time;</script>

</

event>

</

field>

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is the sample file for your reference..

https://acrobat.com/#d=Bty0h7NOTelEJihwUvP80g

I placed the code in the click event of the button.For you to see where the script is...

Select the button and then click on window menu and choose Script Editor.

If you still can not see the Script Editor, then you need to pull the handle down..

See the below image..

https://acrobat.com/#d=eNetdvNNCpH2NIapIXmz5Q

Thanks

Srini

View solution in original post

4 Replies

Avatar

Level 10

Try the modified script.. Place the code in the click event of the "Button1" on your form for testing..

Stamp = new Date();
var Hours;
var Mins;
var Time;
Hours = Stamp.getHours();

if (Hours >= 12) {
Time = " PM";
}
else {
Time = " AM";
}

if (Hours > 12) {
Hours -= 12;
}

if (Hours == 0) {
Hours = 12;
}

Mins = Stamp.getMinutes();

if (Mins< 10) {
Mins = "0" + Mins;
}

xfa.resolveNode("Button1.caption.value.#text").value = Hours + ":" + Mins + Time;

Thanks

Srini

Avatar

Former Community Member

Thank you for your reply. I beleave that this is me not understanding how or where to put this in. I have only really just started to learn scripting so i am below beginer. I did try to enter in the revised code and i could not get it to work, again thank you for your help.

Avatar

Correct answer by
Level 10

Here is the sample file for your reference..

https://acrobat.com/#d=Bty0h7NOTelEJihwUvP80g

I placed the code in the click event of the button.For you to see where the script is...

Select the button and then click on window menu and choose Script Editor.

If you still can not see the Script Editor, then you need to pull the handle down..

See the below image..

https://acrobat.com/#d=eNetdvNNCpH2NIapIXmz5Q

Thanks

Srini

Avatar

Former Community Member

Thank you so much Srini. It work perfectly.

Have a wonderful day

Brandon