Javascript variable into php variable without updating page?

Discussion in 'JavaScript' started by colin008, Jun 14, 2007.

  1. #1
    <SCRIPT LANGUAGE="JavaScript">

    function CalculateSum(Atext, Btext, form)
    {
    var var1
    var A = parseFloat(Atext);
    var B = parseFloat(Btext);
    var C
    form.Answer.value = A - B;
    form.month.value = Math.round(form.Answer.value / 10 *100)/100;
    C = form.month.value;
    location.href="?var1="+C;
    }
    // end of JavaScript functions -->
    </SCRIPT>
    <FORM NAME="Calculator" METHOD="post">
    <P>Total Price: <INPUT TYPE=TEXT NAME="input_A" SIZE=10 value=600></P>
    <P>Deposit: <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P>
    <P>Finance Balance: <INPUT READONLY TYPE=TEXT NAME="Answer" SIZE=12></P>
    <P>Monthly Payment: <INPUT READONLY TYPE=TEXT NAME="month" SIZE=12></P>
    <P><INPUT TYPE="button" VALUE="Recalculate Payment" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P>
    </FORM>
    <? echo $_GET['var1']; ?>

    This works well to get a Javascript variable in to a php variable, however is there another way to do it with out refreshing the page ?
     
    colin008, Jun 14, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    use ajax to make send a variable to php script without refresh.
     
    gibex, Jun 15, 2007 IP
  3. colin008

    colin008 Active Member

    Messages:
    162
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    68
    #3
    Yes i have been reading up on Ajax, i think i will have to give it a go.
     
    colin008, Jun 16, 2007 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @colin008, how did you fixs this???

    i am also in need to get a js variable echoed without refresh
     
    123GoToAndPlay, Aug 9, 2007 IP