首页 > 解决方案 > 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?

标签: php

解决方案


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>


推荐阅读