简体   繁体   English

选中复选框时执行php脚本

[英]Execute php script when checkbox checked

I wanted to do that when my checkbox is checked, a php script whill be executed. 我想在选中我的复选框时执行此操作,将执行一个PHP脚本。 There is my code : 有我的代码:

 <form action="checkboxes.php" method="post"> <input type="checkbox" value="dawid" name="chk1"> 4K </input> <input type="submit" name="Submit" value="Submit"></input> </form> <?php $bdd=new PDO("mysql:host=localhost;dbname=techtronik.pl;charset=utf8", "root"); $wyszukiwanie = $bdd->query("SELECT * FROM procesory "); while($wynik = $wyszukiwanie->fetch() ) { echo $wynik ['nazwaproduktu'] . ". "; } ?> 

Can someone please help me ? 有人可以帮帮我吗 ? Thanks. 谢谢。

I am assuming you have basic knowledge of html, ajax, and javascript. 我假设您具有html,ajax和javascript的基本知识。

In your case you can use ajax call. 您可以使用ajax调用。

1) Checkbox checked 1)选中复选框

2) Call an ajax 2)调用一个ajax

3) Handle ajax and Run php code 3)处理ajax并运行php代码

4) Return to ajax 4)返回ajax

5) Success :) 5)成功:)

Or just submit form on checkbox check then handle with php. 或者只提交复选框复选框,然后使用php处理表单。

You can do it using jQuery, because it's easy solution for beginner. 您可以使用jQuery来完成此操作,因为对于初学者而言,这是简单的解决方案。

Heres the sample jQuery code for your current code: 这是您当前代码的示例jQuery代码:

$('input[name=chk1]').click(function(){
  if($(this).is(':checked')){
    $('form').submit();
    //or your ajax request
  }
});

为什么不使用JavaScript / Ajax,jquery ....并调用check / click函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM