-4

I'm stuck in part of my code for calling the php function in Jquery. Here is my code:

var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 
$('.remaining_amount').html('<?php echo display_money('remaining_amount')?>');// here I need to pass it in to my custom PHP function to show the amount with currency.  

But the problem is that the function display_money taking the variable value as string (remaining_amount) and creating the problem to produce the desired result. some thing like (120$).

Updated: Here is the full code that show how I'm using the remaining_amount, It is changing on the base of selected value.

//show the remaining amount 
            $("#selected_amount").live("change", function(event){
                var total_amount=$('#ta').html();
                var selected_amount=$(this).val();
                if(selected_amount=="")
                {
                    $('.remaining_amount_row').hide();
                    $('.final_withdraw').hide();
                    return false;
                }
                else
                {
                var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);
                $('.remaining_amount').html(remaining_amount);
                $('.remaining_amount_row').show();
                $('.final_withdraw').show();
                return false;
                }
            });
Cœur
  • 37,241
  • 25
  • 195
  • 267
Harshal
  • 3,562
  • 9
  • 36
  • 65

1 Answers1

2

Try to use - load()

var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 
$('.remaining_amount').load('/display_money.php?remaining_amount='+remaining_amount);

display_money.php

if($_GET['remaining_amount'])
{
 // do the required task
}
Shail Paras
  • 1,125
  • 1
  • 14
  • 34
  • Thanks for the answer but value of `remaining amount` is decided at the run time means it is based on `selected_amount` drop down and changes as per the selected value. Another thing is my aim to fix this calculated value to particular place using `.html`. See My updated question. – Harshal Jul 07 '14 at 11:10
  • ok then why `php` inside the `javascript`? you could also use `javascript` to calculate the `remaining_amount`. and also you should keep the `total_amount` in a hidden field. instead of getting as `html()`. – Shail Paras Jul 07 '14 at 11:18
  • Yes that could be the another way to use the java-script function, but i was thought that its better to use function of PHP. – Harshal Jul 07 '14 at 11:21
  • so you have found the solution or not? i think yes. – Shail Paras Jul 07 '14 at 11:31
  • Yes I'm going to use the Java script method for the same functionality having the PHP function. – Harshal Jul 07 '14 at 11:36