Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

if else statements syntax error

Hi,

I am having difficultly with this code...I am sure it has something to do with the semicolon's but I am stumped.

Thanks

function capitalgains()
{
if(document.forms[0].radiobutton1[0].checked)(
  var box = document.forms[0].select.value ;
 document.forms[0].textfield4.value = (box-0);
 )
 else
     { var a = document.forms[0].textfield3.value;
(document.forms[0].textfield4.value = (a-0)/2);
}

   
}
</script>
0
gweston2003
Asked:
gweston2003
  • 3
  • 2
  • 2
  • +1
1 Solution
 
WakieCommented:
function capitalgains()
{
if(document.forms[0].radiobutton1[0].checked);
 var box = document.forms[0].select.value;
document.forms[0].textfield4.value = (box-0);
}
else
    {
var a = document.forms[0].textfield3.value;
document.forms[0].textfield4.value = (a-0)/2;
}

   
}
</script>
0
 
msmalesCommented:
Looks like you're using JavaScript.

qweston2003,
I can easily see your problem there. Your opening and closing brackets of your IF statement are round brackets which should have curly brackets instead.

Wakie's example above also have a syntax error. The problem is the semi-colon after the IF statement header which should have an opening curly bracket.

Martin
0
 
msmalesCommented:
And by the way, make sure you also have a <script> tag to complement with the closing </script> tag.

Martin
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gweston2003Author Commented:
Thanks guys
I still can't get ...I put a curly bracket after If and IE tells me it wants a regular bracket...?

Here's what I have now

<script type="text/javascript">
function capitalgains()
{
if{document.forms[0].radiobutton1[0].checked};
var box = document.forms[0].select.value;
document.forms[0].textfield4.value = (box-0);
}
else
   {
var a = document.forms[0].textfield3.value;
document.forms[0].textfield4.value = (a-0)/2;
}

 
}
</script>
0
 
AndrewKCommented:
no - msmales was talking about this:

function capitalgains()
{
if(document.forms[0].radiobutton1[0].checked)
   {
      var box = document.forms[0].select.value ;
      document.forms[0].textfield4.value = (box-0);
   }
else
   {
      var a = document.forms[0].textfield3.value;
      document.forms[0].textfield4.value = ((a-0)/2);
   }
}


0
 
gweston2003Author Commented:
This is my first time using this site...I am not sure if I am doing this correctly I should have accepted all three answers...
0
 
AndrewKCommented:
You should have accepted msmales answer - he meant what I wrote. Mine may have been clearer, but that's what he meant! Equally, you can only accept one answer - just use your judgement as to which answer helped you out the most. If none help, don't accept them (but always be polite and say why!). Also, only accept an answer after you have verified that it really works for you.
0
 
msmalesCommented:
Looks like Andrew's answer is a LOT clearer than mine :)

Besides, if it were up to me, I would definitely accept Andrew's answer, so don't be modest Andrew! :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now