2014-02-14 72 views
0

我的表格:腓後形式的onkeyup功能

<tfoot> 
     <form method="post" action="kategoriler.php"> 
    <tr> 
    <th>Select</th> 
    <th><input type="text" name="id" id="id" class="form-control" style="width:80px;" placeholder="#"></th> 
    <th>Image</th> 
    <th><input type="text" name="name" id="name" class="form-control" style="width:120px;" placeholder="Name"></th> 
    <th>Order</th> 
    <th><input type="text" name="Visibility" id="Visibility" class="form-control" style="width:120px;" placeholder="Visibility"></th> 
    <th>Date</th> 
    <th>Edit</th> 
    </tr> 
    </form> 
    </tfoot> 

我想我怎麼能發送此表單值後用JSON和功能的onkeyup這個值?

+0

與onkeyup事件?非常糟糕的主意 –

+0

你的想法是什麼?我不擅長jquery –

+0

你可以使用[jQuery.ajax()](http://api.jquery.com/jQuery.ajax/) – Jai

回答

1

該作品增添KEYUP功能對所有輸入型的形式

$('form input:text').keyup(function(){ 
     var data = $("form").serialize(); 
     $.ajax({ 
     url: 'kategoriler.php', 
     data: data, 
     dataType:'json', 
     type:'POST', 
     async:false, 
     success: function(data) { 
      alert('submitted'); 
     } 
}); 

如果你想添加KEYUP在一個特定的輸入類型,然後只是更換

$('form input:text').keyup(function(){ 

隨着

$('#id').keyup(function(){ 
+0

中描述的那樣得到相同的值。我怎麼能得到這個值在kategoriler.php例如我發送的名字,但我不能把這個名字其他頁面 –

+1

使用$ _POST ...像$ all_input_values = $ _POST然後$ all_input_values ['id']這會得到你的id值..其他 –

1

使用jQuery AJAX爲:

$(document).keydown(function(e) { 
    $.ajax({ 
       type: "POST", 
       dataType: "json", 
       url: "kategoriler.php", 
       data: {name: $('#name').val() //ETC...}, 
       success: function (html) { 
       alert('ok'); 
       } 
     }); 
    }); 
+0

** onkeyup ** op想要提交表單在這個事件。 – Jai

+0

當我按下任何按鈕時,此方法將工作? –

+1

我編輯我的文章;) –

0

,你可以不喜歡這樣。前提是你whant提交表單在任何KEYUP

//trigger form submit 
$(document).keyup(function(){ 
    $("form").submit(); 
}); 

//Do what you whant with your form 
$("form").submit(function(){ 
    //Do something eg. ajax call 
     $.ajax({ 
      type: "POST", 
      dataType: "json", 
      url: "kategoriler.php", 
      data: {name: $('#name').val() //ETC...}, 
      success: function (html) { 
       alert('ok'); 
      } 
     }); 
}); 
+0

我有沒有提交按鈕,我想處理,當我按任何按鈕? –

+0

好的。但當用戶在文本框中輸入內容時,這不是問題嗎?這意味着表單會針對每個角色提交。在我看來,它會更方便onChange()。 –

+0

我怎樣才能得到這個值:) –