LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2005, 10:52 AM   #1
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Rep: Reputation: 30
if - else


function doSalesTax(field,form) {

if (field.checked)

form.tax_amt.value = formatDecimal(

<?php echo isset($cur_sales_tax)? $cur_sales_tax: 0 ?> * form.sub_tot.value );

else form.tax_amt.value = 0;

if (form.sub_tot.value > 0) doTotals(form);


Hi,
I am not a programer. Hobby, so to say. This function adds the SalesTax only if the field is checked. I would like to do the opposite: SalesTax is added if the field is not checked. If the field is checked, the SalesTax is 0%. What should I change/add? Thanks.
 
Old 04-14-2005, 11:02 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Code:
if (!field.checked)

form.tax_amt.value = formatDecimal(

<?php echo isset($cur_sales_tax)? $cur_sales_tax: 0 ?> * form.sub_tot.value );

else form.tax_amt.value = 0;

if (form.sub_tot.value > 0) doTotals(form);
 
Old 04-14-2005, 11:03 AM   #3
marghorp
Senior Member
 
Registered: Jan 2004
Location: Slovenia
Distribution: Slackware 10.1, SLAX to the MAX :)
Posts: 1,040

Rep: Reputation: 45
You are checking the field.checked with the if condition. The condition looks like this:

if(field.checked) -----> this is true when the field is checked.

You want it true when the field is unchecked, just reverse the condition.

You can reverse a condition by putting a ! sign in front of it, like this:

if(!field.checked) ------> this will be true when the field is not checked.
 
Old 04-14-2005, 11:49 AM   #4
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
Thanks, it works great but my question, my fault, was not put the right way.
I still have to check the box for the tax amount to appear in the field.
However if I uncheck the box, the tax remains displayed.
How can I display the tax without checking - unchecking the box?
The tax amount 0.00 should display if the box is checked.

I am not sure I provide all necessary variables in this post...

Here is the code which does it:
Code:
// VAT 

if ( isset($state) && !empty($state) && isset($cur_sales_tax) && !empty($cur_sales_tax) ) {

  $class = ($class == 'even')? 'odd': 'even';

  echo '<tr class="' . $class . '">

	 <td colspan="2">Check if you live outside ' . $state . '

    <input type="checkbox" name="sales_tax" tabindex="' . ($num_products + 2) . '" onclick="doSalesTax(this,this.form)"></td>

	 <td class="lbl" colspan="2">VAT 21%:

   &euro;<input class="cur" type="text" name="tax_amt" size="8" value="0" readonly onfocus="this.blur()"></td>

 </tr>

';

}
 
Old 04-14-2005, 12:53 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Try add in your body (say your form name is 'MyForm') :
Code:
<body onload="doSalesTax(document.MyForm.sales_taxfield, document.MyForm);">
That's way the doSalesTax() is called as soon as the page is loaded
 
Old 04-14-2005, 02:14 PM   #6
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
Great!
This almost does the trick.
The only problem is that I have to reload (refresh) the page for the TAX to show up in the field.
Some mysterious script which would do it without refreshing is missing.
Thanks a lot!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration