svenson
svenson

Reputation: 39

How to pass value from textbox to another page without form

Ok i have this code and i want to send this price from and price to to some other page when user clicks on submit but without refreshing page and without form.On other page i will use this inputs for sql query and display results.

Price from:<input type="text" name="from" id="from" width="50px" />
Price to:<input type="text" name="to" id="to" width="50px" />
<input type="submit" id="submit" value="Search"/>

Upvotes: 0

Views: 4494

Answers (3)

var _from = $('#from').val(); 
var _to   = $('#to').val();    
$.post('your_file.php',{from: _form, to: _to},function(data){
    //Do Something with returned data.
},'json');

'json' at the end could also be 'html' depending upon what you're returning.

Upvotes: 0

iLaYa  ツ
iLaYa ツ

Reputation: 3997

Hi you can achieve this using jQuery+Ajax, try this

$('#submit').click(function(event) {

        var from = $('#from').val(); 
        var to   = $('#to').val();
        $.ajax({
                type: "POST",
                url: "page_name.php",
                data:"from="+from+"&to="+to,
                success: function (msg) {

                    //some action
                }
            });

    });

and in your php(page_name.php) file you can get the posted value and can do the necessary operation

$from = $_POST['from'];
$to   = $_POST['to'];

Upvotes: 0

Pragnesh Chauhan
Pragnesh Chauhan

Reputation: 8476

using jquery

$('#submit').click(){
  event.preventDefault();// prevent form from submitting
   $.ajax({
     type: 'POST',
     url: 'targetpage.php', //your page here
     data: {price_from:$('#from').val() , price_to: $('#to').val()},
     success: function(response){
     }
  });
});  

Upvotes: 1

Related Questions