Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

javascript to insert address with checkbox option causing clearing of user entered address on save

Avatar

Former Community Member

I have a checkbox that will enter our company address into the address fields when checked, but when unchecked the user has the option to enter their own address.

This works fine until it comes to saving the document. When the checkbox is unchecked and the user enters their own address and then saves the document, the javascript is removing the user entered address.

Here is the code:

<event activity="initialize" name="event__initialize">
<script>if ($.rawValue eq 1) then
form1
.Main.Address1="blah blah Street"
City = "London"
ZipCode = "WC1N XXX"
Country = "UK"
elseif
(ros.rawValue eq 1) then
form1
.Main.Address1="blah blah Street"
City = "London"
ZipCode = "WC1N XXX"
Country = "UK"

else

Address1 = null

City = null

ZipCode = null

Country = null

endif
</script>
</event>
<event activity="change" name="event__change">
<script>if ($.rawValue eq 1) then
form1
.Main.Address1="blah blah Street"
City = "London"
ZipCode = "WC1N XXX"
Country = "UK" elseif (ros.rawValue eq 1) then
form1
.Main.Address1="blah blah Street"
City = "London"
ZipCode = "WC1N XXX"
Country = "UK"

else

Address1 = null

City = null

ZipCode = null

Country = null

endif
</script>
</event>

Any ideas?

EDIT:

It's this part of the script that is causing it:

    else

    Address1 = null

    City = null

    ZipCode = null

    Country = null

I need a way to say user-entered-data:

    else

    Address1 = user-entered-data

    City = user-entered-data

    ZipCode = user-entered-data

    Country = user-entered-data

(Notes: I am saving it as a reader-extended pdf so the text entered in the fields by the user can be saved)

Thanks in advance

1 Reply

Avatar

Level 10

Hi,

I think you need an else condition, so change

 

else

Address1 = null

City = null

ZipCode = null

Country = null

endif

to somthing like

elseif ($.rawValue ne 2) then

Address1 = null

City = null

ZipCode = null

Country = null

endif

Regards

Bruce