php - How to post a button's value in html form (PHP)
问题描述
i have javascript that changes an input's value and when i post the form, the field is not transferred
<input id="exampleID" type="button" name="exampleButton" value="click me" onclick="changeValue()">
when the button is clicked the value (displayed to the user) changes to "Clicked"
then when i post the form it the value is left behind
if(isset($_POST['exampleButton'])) {
echo "true";
}
this doesn't echo anything
what should i do?
解决方案
You can change value of hidden field:
<input id="exampleID" type="hidden" name="exampleButton" value="">
<input type="button" value="click me" onclick="changeValue()">
<script>
function changeValue(){
document.getElementById('exampleID').value = "Clicked";
}
</script>
推荐阅读
- dynamics-crm - Dynamics CRM 中的安全字段
- cmake - 设置 CMAKE_CXX_FLAGS 是否比 add_compile_options 更好
- r - 为什么我的 Dollar_format() 函数中没有应用“比例”参数
- java - Heroku can't find or load main class
- python - 图像索引超出范围,但不应该是
- javascript - 如何将静态标签与动态创建的表单的滚动容器对齐?
- python - 以字典为值的二维数组?
- html - 无法弄清楚为什么我的主要元素上的背景颜色不会改变
- awk - How to remove duplicate lines without sorting and only matching nth colum
- continuous-integration - Azure Pipeline Nuget Package Versioning Scheme, How to Get "1.0.$(Rev:r)"