?
Solved

if else statements syntax error

Posted on 2003-02-26
8
Medium Priority
?
136 Views
Last Modified: 2010-04-06
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
Comment
Question by:gweston2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:Wakie
ID: 8030824
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
 
LVL 1

Expert Comment

by:msmales
ID: 8030874
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
 
LVL 1

Expert Comment

by:msmales
ID: 8030883
And by the way, make sure you also have a <script> tag to complement with the closing </script> tag.

Martin
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

by:gweston2003
ID: 8030911
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
 
LVL 2

Accepted Solution

by:
AndrewK earned 200 total points
ID: 8030954
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
 

Author Comment

by:gweston2003
ID: 8030998
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
 
LVL 2

Expert Comment

by:AndrewK
ID: 8031033
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
 
LVL 1

Expert Comment

by:msmales
ID: 8031472
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question