...

View Full Version : help putting two scripts together?



angst
12-22-2005, 03:46 PM
Hi,
I'm trying to put two scripts together,


first script:

function Add(){
var tx=document.forms[0].TaxAmount;
var ot=document.forms[0].order_total;
var q=document.forms[0].qty;
var c=document.forms[0].price_each;
var t=document.forms[0].amount;
var tt=document.forms[0].TotalTemp;
if (isNaN(q.value)||isNaN(c.value)){
q.value=q.value.replace(/\D/g,'');
c.value=c.value.replace(/\D/g,'');
tx.value=tx.value.replace(/\D/g,'');
ot.value=ot.value.replace(/\D/g,'');
t.value=ot.value.replace(/\D/g,'');
alert('Only Numbers Allowed');
}
if (q.value.length>0&&c.value.length>0){
t.value=parseFloat(q.value) * parseFloat(c.value);
temp = t.value * tx.value / 100;
temp2 = parseFloat(temp) + parseFloat(tt.value) + parseFloat(t.value);
ot.value = Math.round(temp2*100)/100;
}
}


I want to be able to split this value,
var tx=document.forms[0].TaxAmount;

like I've done here:
function TaxDrop(selectIndex) {
var TaxArray=selectIndex.split("|");
document.firstForm.TaxAmount.value = TaxArray[0];
document.firstForm.TaxID.value = TaxArray[1];
}

the problem is, that I need these two scripts to work together.
and right now they just wont work, like the first script Add() to be able to pick up values from TaxDrop, currently I've tried putting the TaxDrop values into hidden text fields, but I guess because there are no user clicks on those fields the Add() script wont pick them up,

can anyone please tell me what I need to do to make this both work together? or just make one script from the two ?

thanks in advance for your time!
-Ken

NancyJ
12-22-2005, 03:57 PM
Not entirely sure exactly what you're trying to do, what fires the Add() function? At what point do you want to split tx?

to split that value you just need to do

TaxDrop(tx)

angst
12-22-2005, 03:57 PM
.....

angst
12-22-2005, 03:59 PM
well,
most of the fields are like this:

<input type="text" name="price_each" class="dateinput" size="4" value="<%=price_each%>" onkeyup="Add();" />

so each time you enter an amount, it updates the total.

-Ken

angst
12-22-2005, 04:10 PM
ok,
let me start again,

I've got this script:


function Add(){
var tx=document.forms[0].Tax;
var ot=document.forms[0].order_total;
var q=document.forms[0].qty;
var c=document.forms[0].price_each;
var t=document.forms[0].amount;
var tt=document.forms[0].TotalTemp;
if (isNaN(q.value)||isNaN(c.value)){
q.value=q.value.replace(/\D/g,'');
c.value=c.value.replace(/\D/g,'');
tx.value=tx.value.replace(/\D/g,'');
ot.value=ot.value.replace(/\D/g,'');
t.value=ot.value.replace(/\D/g,'');
alert('Only Numbers Allowed');
}
if (q.value.length>0&&c.value.length>0){
t.value=parseFloat(q.value) * parseFloat(c.value);
temp = t.value * tx.value / 100;
temp2 = parseFloat(temp) + parseFloat(tt.value) + parseFloat(t.value);
ot.value = Math.round(temp2*100)/100;
}
}

I want to split this value using | ( pipe )
var tx=document.forms[0].Tax;

then be able to pass the first value of the array
to the rest of the Add() script,
the second value I want to just write to a text field.


do you see what I mean?

I'm completly stuck on this one,, no matter what I try, the script brakes.

any thoughts?

thanks again,
-Ken

Nischumacher
12-22-2005, 05:23 PM
although i did not understand exactly what you need... i understood the part where you need to split the value of this...

var tx=document.forms[0].Tax;

you could do this...
var tx=document.forms[0].Tax.value.split("|")[0]
to get the first value...

and
document.forms[0].Tax.value.split("|")[1]
to get the second value...

angst
12-22-2005, 06:01 PM
ah,
i got it with a little less code then that:



function Add(){

//var tx=document.forms[0].TaxAmount;
tax=document.forms[0].tax.value;

TaxArray = tax.split("|");
var pst = TaxArray[0];
var gst = TaxArray[1];
var tx = parseFloat(gst) + parseFloat(pst);

document.firstForm.CurrentPST.value = TaxArray[0];
document.firstForm.CurrentGST.value = TaxArray[1];
document.firstForm.TaxID.value = TaxArray[2];

var gstt=document.forms[0].pst_total;
var pstt=document.forms[0].gst_total;
var ot=document.forms[0].order_total;
var q=document.forms[0].qty;
var c=document.forms[0].price_each;
var t=document.forms[0].amount;
var tt=document.forms[0].TotalTemp;

if (isNaN(q.value)||isNaN(c.value)){
q.value=q.value.replace(/\D/g,'');
c.value=c.value.replace(/\D/g,'');
ot.value=ot.value.replace(/\D/g,'');
t.value=ot.value.replace(/\D/g,'');
alert('Only Numbers Allowed');
}
if (q.value.length>0&&c.value.length>0){
t.value=parseFloat(q.value) * parseFloat(c.value);
temp = t.value * tx / 100;
temp2 = parseFloat(temp) + parseFloat(tt.value) + parseFloat(t.value);
ot.value = Math.round(temp2*100)/100;


pstt.value = parseFloat(q.value) * parseFloat(t.value) * pst / 100;// + parseFloat(pstt.value);
gstt.value = parseFloat(q.value) * parseFloat(t.value) * gst / 100;// + parseFloat(gstt.value);
}
}
</script>


thanks for your help!!:)
-Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum