Jump to content

Input Field Affect Being Affected by a Function


Wayniac

Recommended Posts

Below is my previous code I had working in the manner it would change the price, sub_total, tax, sh, total, and total_paid input fields to 0. There are two problems with this...

 

1. When it outputs to the input fields, the value displays as 0 instead of 0.00.

2. I need to have it only react when the value typed into the input field "trees_sold" is "0". If any higher, I would like it to ignore the statement.

 

<!-- Comp all prices to zero value -->
<SCRIPT LANGUAGE="JavaScript">
var trees_sold = 0.00;

function InitSaveVariables(form) {
price = form.price.value;
sub_total = form.sub_total.value;
tax = form.tax.value;
sh = form.sh.value;
total = form.total.value;
total_paid = form.total_paid.value;
}

function CompPrices(form) {
if (trees_sold == 0.00) {
InitSaveVariables(form);
form.price.value = 0.00;
form.sub_total.value = 0.00;
form.tax.value = 0.00;
form.sh.value = 0.00;
form.total.value = 0.00;
form.total_paid.value = 0.00;
}
}
</script>

 

<input name="trees_sold" id="trees_sold" size="15" onkeyup="javascript:CompPrices(this.form);" maxlength="15" />

 

Below is my current code I'm working with that I can't seem to get to function properly. I've modified the first two lines of code here, and am attempting to pull any data that is typed in and automatically take into consideration if it is a "0" value, it reacts as my code below says "if (trees_sold == 0.00)" and if anything else, it will not do anything. This is not working unfortunately.

 

<!-- Comp all prices to zero value -->
<SCRIPT LANGUAGE="JavaScript">
form.trees_sold.value = "";
trees_sold = form.trees_sold.value;

function InitSaveVariables(form) {
price = form.price.value;
sub_total = form.sub_total.value;
tax = form.tax.value;
sh = form.sh.value;
total = form.total.value;
total_paid = form.total_paid.value;
}

function CompPrices(form) {
if (trees_sold == 0.00) {
InitSaveVariables(form);
form.price.value = 0.00;
form.sub_total.value = 0.00;
form.tax.value = 0.00;
form.sh.value = 0.00;
form.total.value = 0.00;
form.total_paid.value = 0.00;
}
}
</script>

 

<input name="trees_sold" id="trees_sold" size="15" onkeyup="javascript:CompPrices(this.form);" maxlength="15" />

 

Anyone have any ideas?

 

Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.