尝试通过 JS 将一些参数传递给 PHP 时,我遇到了一些问题。
情况如下:
HTML:
<form id="numbtns" method="post" action="imphp.php">
<button id="1" onClick="pass(this.id)">1</button>
<button id="2" onClick="pass(this.id)">2</button>
<button id="3" onClick="pass(this.id)">3</button>
<button id="confirm" onClick="save()">submit</button>
</form>
JS:
pass(clicked_id) {
var btn = document.getElementById(clicked_id);
**// I have no idea what to do next to give the ids to the php file.**
}
save() {
**// I want function save() to collect the parameters from function pass(), and pass them to 'imphp.php' when submit button is clicked. I'm stuck here.**
}
PHP:
// connection part, let's skip it.
...
$num = $_POST['num'];
$query = sprintf("SELECT id, num FROM tb WHERE num = $num");
我知道这对你来说可能是一个快速而愚蠢的问题,但我几个小时都想不通。所以......谁能帮助我,我将非常感激。
提前谢谢。