Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    help putting two scripts together?

    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

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    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
    Code:
    TaxDrop(tx)

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    .....
    Last edited by angst; 12-22-2005 at 04:10 PM.

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok,
    let me start again,

    I've got this script:
    PHP Code:
    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

  • #6
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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...
    - NS 666
    .net DEVILoper

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ah,
    i got it with a little less code then that:

    PHP Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •