0
 <div class="wrap-input100 validate-input bg1 rs1-wrap-input100">
                <div class="contact100-form-btn" id="add_driver">
                <span>
                Add another Driver
                <i class="fa fa-long-arrow-right m-l-7" aria-hidden="true"></i>
                </span>
                </div>
            </div> 


<script>    
 var count = 0;
 jQuery("#add_driver").click(function(){
 count++;
 }); </script>

how can i pass the value of the variable count to the next page using php sessions or any other method? is there any simple way to do it?

8
  • 1
    you can use ajax to pass value to next page Commented Jun 20, 2018 at 11:02
  • is there no way other than ajax? Commented Jun 20, 2018 at 11:03
  • 1
    What exactly are you trying to achieve here? Commented Jun 20, 2018 at 11:03
  • i need to pass the values to the other page that's it. Commented Jun 20, 2018 at 11:04
  • Then it sounds like sending the value to the next page in the querystring would be the simplest way Commented Jun 20, 2018 at 11:06

2 Answers 2

2

Using Below code you can send count value to secondpage.php and in second page use $_POST['count_var'] to access variable. You can check your success response in success: function (response)

<script>    
 var count = 0;
 jQuery("#add_driver").click(function(){
 count++;
 $.ajax({
                        type: 'post',
                        url: 'secondpage.php',
                        data: {
                            count_var: count,

                        },
                        success: function (response) {
                             document.getElementById("divid").innerHTML = response;
                        }
                    });
 }); 

 </script>
Sign up to request clarification or add additional context in comments.

1 Comment

it is the id where u want to show your response, Ex : id of <div> tag
1

use localStorage

page one

var count = 0;
 jQuery("#add_driver").click(function(){
     count++;
     localStorage.setItem("count", count);
 });

page two

 alert(localStorage.getItem("count"));

Should be the same domain

3 Comments

i need the value of count in the php script.
@NEETHINNambiar then there are two way you can accomplish this: ajax and cookie. what method you like ?
@NEETHINNambiar ok you got your answer, gl

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.