0

Here is my Javascript for fetching value to input box,

$('#edituserModal').on('show.bs.modal', function(e) {
    var userid = $(e.relatedTarget).data('userid');
    var u_id = document.getElementById('hdn_user_id').value = userid;
    alert(userid);
});

I want this value to use for SQL query in modal window which is on same page. I fetched value in modal window but unable to use it. What the format to use it.

2
  • show modal code Commented Sep 21, 2016 at 6:58
  • You Can't, Just use in another page(or action) otherwise display(or operate) using Javascript/Jquery variable Commented Sep 21, 2016 at 7:05

2 Answers 2

1

You can pass js variable into php page using ajax.

$('#edituserModal').on('show.bs.modal', function(e) {
var userid = $(e.relatedTarget).data('userid');
var u_id=document.getElementById('hdn_user_id').value=userid;

 $.ajax({    //create an ajax request to load page.php
        type: "GET",
        url: "page.php",

        data:"varabletophp="+u_id,    //Here is the value you wish to pass in to php page        
        dataType: "html",   //expect html to be returned                
        success: function(response){                    

          alert(response);
        }

    });  

});

No you can get this variable into your page.php (php page) using

$fromjs=$_GET['varabletophp'];
echo $fromjs;
Sign up to request clarification or add additional context in comments.

Comments

0

you can use input hidden and set userid value in on this input so , post form

Varying modal content based on trigger button : http://getbootstrap.com/javascript/#modals-related-target

        var data = new FormData($('form#' + formId)[0]);

        $.ajax({
            type: "POST",
            url: url,
            data: data,
            cache: false,
            processData: false,
            contentType: false,
            beforeSend: function () {

            },
            success: function (response) {


            },
            error: function (response) {

            }
        });

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.