Click to See Complete Forum and Search --> : Help with Date calculation and if else statement


JAG
10-21-2003, 09:43 AM
I am a novice and trying to do simple scripts is difficult for me, so please forgive my simple questions.

NOTE: I am making a form out of a .pdf file

I have been trying to write 2 different scripts.

1. If I enter a date in field "1" then the next six days is automatically filled into 6 separate fields. This is for a travel voucher. Example: Someone puts 1/1/03 into the field for Sunday, then instead of them having to enter 1/2/03 on Mon, etc, it will be completed for them.

Second question,

2. If a positive number shows in a particular field, then that amount shows up in a corresponding field. If it is negative then it shows up in a different field. Example: "Total Remaining Expenses" if positive, then amount shows up in "Balance Due Employee", if negative, then shows up in "Balance Due ABC Company" (but what shows up in this field should be the number w/o the negative sign).

I hope this is clear enough for anyone to be able to get me going. I appreciate anyone's inputs!

Khalid Ali
10-21-2003, 09:54 AM
show us what you have done so far,and some one will be able to guide you from there

clairec666
10-21-2003, 09:54 AM
An answer to the second question:

1. Call a function when the user submits the form so that you can access the values in the form
2. Assign the value from the field you want to access to a variable: eg. var value1 = document.formname.fieldname.value;
3. Test if it is bigger than 0. If it is, the variable 'positive' is assigned a 'true' value, if not, it is false:
if (value1 >= 0) var positive = true;
else positive = false;
4.
if (positive == true) {
var balance_due = value1;
var balance_owe = 0;
}
if (positive == false) {
var balance_due = 0;
var balance_owe = value1*-1;
}

Is that the sort of thing you wanted?

Charles
10-21-2003, 04:00 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.ONE_DAY = Date.ONE_HOUR * 24;
// -->
</script>

<form action="">
<div>
<label>First Day<input type="text" onchange="var d = new Date(this.value); for (var i=0; i<7; i++) {this.form.elements[i].value = new Date(i * Date.ONE_DAY + d.getTime()).toDateString()}"></label>
<label>Second Day<input type="text"></label>
<label>Third Day<input type="text"></label>
<label>Fourth Day<input type="text"></label>
<label>Fifth Day<input type="text"></label>
<label>Sixth Day<input type="text"></label>
<label>Seventh Day<input type="text"></label>
</div>

<div>
<label>Total Remaining Expenses<input type="text" onchange="this.previousSibling.data = this.value > 0 ? 'Balance Due Employee' : 'Balance Due ABC Company'"></label>
</div>
</form>

But what about those good people who do not use JavaScript?