2012-10-19 122 views
0

好吧,我有這段代碼,我想從這個價格和價格發送到其他頁面,當用戶點擊提交但沒有刷新頁面和沒有窗體。在其他頁面我將使用這個輸入進行sql查詢並顯示結果。如何將值從文本框傳遞到另一個頁面沒有表格

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"/> 
+3

閱讀關於javascript/jQuery中的ajax – ankur140290

回答

0

嗨,你可以做到這一點使用jQuery + Ajax的,試試這個

$('#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 
       } 
      }); 

    }); 

,並在你的PHP(page_name.php)文件,你可以得到張貼價值,可以做必要的操作

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

你是否因爲錯誤而錯過了括號? – svenson

+0

嘗試新的答案。實際上'''在''page_name.php'的末尾丟失了。現在更正。 –

1

使用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){ 
    } 
    }); 
}); 
0
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'最後也可能是'html'取決於你要返回什麼。

相關問題