Newbie Question - should be easy

I have created a form which has a check box. When the user clicks it, I want the value of a field to be replaced by the current value of another field. here is my code that I thought should work:
(
if usemainaddressasdelivery = ‘1’
deliverysuburb = suburb
else
deliverysuburb = “”
)

On verify I get a syntax error on line 3 pos 2. I know this will be simple but I am new and need a bit of steering. I could not find any exmaples of this simple method in the example.

Dave

I have just discovoured my brackets were wrong and that I needed them around the evaluation after if. BUT, now it works with out a syntax error, but the check box stays contantly ticked (MySQL enum ‘0’, ‘1’) and no change to the field occurrs???

can you post your method code?

You should indeed post the code exactly as you use it, so we can fgure out the problem.

One thing goes wrong for sure here

Instead of

if usemainaddressasdelivery = ‘1’

you should do

if (usemainaddressasdelivery == 1)

Comparison has to be used with double == and that field usemainaddressasdelivery is probably an integer, so you can use 1 instead of ‘1’.

Thanks All - fixed it. Used == and changed it to 1 not ‘1’.

My code works a treat now. Thank you for your fast response. I feel well supported and think I will go a long way fast with this product.
:D

My guess is your code looks something like this:

if (usemainaddressasdelivery = '1' )
{
	deliverysuburb = suburb 
}
else
{ 
	deliverysuburb = "" 
}

If so then you are assigning a 1 to the usemainaddressasdelivery everytime you run this method.
When you want to check a condition you have to use double equal signs.
Thus your code should look like this.

if (usemainaddressasdelivery == '1' )
{
	deliverysuburb = suburb 
}
else
{ 
	deliverysuburb = "" 
}

It’s a common mistake/typoo.
A little tip that Jan Aleman showed us at the training in Utrecht is the following.
You could learn yourself to work the other way around. Like this:

if ('1' = usemainaddressasdelivery )

When you make a mistake (like in this code) it will give an error since you can’t assign to a value.

Or you can use:

if (usemainaddressasdelivery.equals('1'))

HTH

Wow, looks like we were posting answers all at the same time. :D