1

How to add the value of php variabele to jquery variable and adds them,i have a form that will take a value and post to second page where second page contains a div panel where the form checkboxes values are adding and subtracting,basically i want to add the submitted value from page1 to page2.Here is the code.I have 3 form values which will be redirected one by one.Whenever user submits the respective button

if($_POST['submit'])
{
$beg=$_POST['basic'];
}

function refreshPrices() {

    var currentTotalValue = 0;
    var beg=?????
    $("#results div").each(function() {
        if (!isNaN(parseInt($(this).find("span").text().substring(1)))) {
            currentTotalValue += parseInt($(this).find("span").text().substring(1));
        }
    });


    $("#totalValue").text("$" + currentTotalValue)
}

5 Answers 5

1
var beg=<?php echo $beg; ?>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

var beg = '<?php echo $beg ;?>';

if you want to add to the total value you can do this:

currentTotalValue = currentTotalValue + parseInt(beg);

Comments

0

its better to do it this way :

var js_var = '<?=json_encode($php_var);?>';

This way you will be able to transfer any type of data to js (arrays, objects, strings, etc.) and access it easily like this:

js_var['element']

2 Comments

Is this a correct code currentTotalValue = currentTotalValue + parseInt(beg) + parseInt(int) + parseInt(adv);
So? I don't say that it's the only possible solution. I was just truing to help.
0
var beg = '<?php echo $beg ;?>';

But this can be only one once during the load of the page. After that we cant assign a server side script to js.

8 Comments

Is this a correct code currentTotalValue = currentTotalValue + parseInt(beg) + parseInt(int) + parseInt(adv);
on condition that beg,int and adv are js variables
var beg = '<?php echo $beg ;?>'; var inte = '<?php echo $int ;?>'; var adv = '<?php echo $adv ;?>';
are you doing this only during page load? I mean this operation is done once?
php post variables,only adding 1 variable i-e beg to this code currentTotalValue = currentTotalValue + parseInt(beg) + parseInt(int) + parseInt(adv);
|
0

Retrieve value by input class or id like dat

var beg = $("#basic").val();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.