Php “重置”按钮以清除表单字段

Php “重置”按钮以清除表单字段,php,html,reset,Php,Html,Reset,我有以下代码: <form id="selectform" method="post"> From Box #: <input id="from" type="text" style="width: 40px;" name="from" value="<?php echo $from;?>" /> To Box #: <input id="to" type="text" style="width: 40px;" name="to" val

我有以下代码:

<form id="selectform" method="post">
    From Box #: <input id="from" type="text" style="width: 40px;" name="from" value="<?php echo $from;?>" />
    To Box #: <input id="to" type="text" style="width: 40px;" name="to" value="<?php echo $to;?>" />
    <button type="submit">UPDATE</button>
    <button onkeydown="document.getElementById('from').value=null;document.getElementById('selectform').reset;" type="reset">CLEAR ENTRY</button>
</form>

从方框#:简单解决方案
将按钮更改为:

<button onclick="document.getElementById('selectform').reset(); document.getElementById('from').value = null; return false;">
    CLEAR ENTRY
</button>
在JavaScript中,您可以添加一个单击事件:

// Get all the reset buttons from the dom
var resetButtons = document.getElementsByClassName('reset');

// Loop through each reset buttons to bind the click event
for(var i=0; i<resetButtons.length; i++){
  resetButtons[i].addEventListener('click', resetForm);
}

/**
 * Function to hard reset the inputs of a form.
 *
 * @param object event The event object.
 * @return void
 */
function resetForm(event){

  event.preventDefault();

  var form = event.currentTarget.form;
  var inputs = form.querySelectorAll('input');

  inputs.forEach(function(input, index){
    input.value = null;
  });

}
//从dom获取所有重置按钮
var resetButtons=document.getElementsByClassName('reset');
//循环遍历每个重置按钮以绑定单击事件
对于(var i=0;i简单解决方案
将按钮更改为:

<button onclick="document.getElementById('selectform').reset(); document.getElementById('from').value = null; return false;">
    CLEAR ENTRY
</button>
在JavaScript中,您可以添加一个单击事件:

// Get all the reset buttons from the dom
var resetButtons = document.getElementsByClassName('reset');

// Loop through each reset buttons to bind the click event
for(var i=0; i<resetButtons.length; i++){
  resetButtons[i].addEventListener('click', resetForm);
}

/**
 * Function to hard reset the inputs of a form.
 *
 * @param object event The event object.
 * @return void
 */
function resetForm(event){

  event.preventDefault();

  var form = event.currentTarget.form;
  var inputs = form.querySelectorAll('input');

  inputs.forEach(function(input, index){
    input.value = null;
  });

}
//从dom获取所有重置按钮
var resetButtons=document.getElementsByClassName('reset');
//循环遍历每个重置按钮以绑定单击事件

对于(var i=0;iTHANKS!!!这太棒了。作为一名兼职程序员,细微差别有时对我来说太微妙了。我将保存整个解决方案,因为它可能在网站的其他部分对我有所帮助。谢谢!!!这太棒了。作为兼职程序员,细微差别有时对我来说太细微了。我将保存整个解决方案,因为它可能在网站的其他部分对我有所帮助。