I have two buttons of type="submit" one for submitting to the database and other for updating the database and for the same purpose I got two PHP files one for submitting and other for updating.
The problem is that I want to hide update button on fist.php and show the submit button and vice-versa.
Let's say the page, which has the two buttons you mentioned, send a request to query existing record. If no record found, the page is supposed to submit to "submit" page, else to "update" page.
Then, in your code, you can put a hidden input element, which contains the value, by which you know where to submit. maybe something like this:
<input type="text" id="direction" value="" display="hidden">
Then, you have a button, not a type=submit, but a type=button. something like this:
<input type="button" id="submitBtn" value="submit" onclick="submitForm()">
Then you have a javascript function. something like this:
<script language="javascript">
function submitForm(){
if(document.getElementById("direction").value=="submit"){
//Change form1 to your real form name.
document.form1.action="submit.php";
document.form1.submit();
}else if(document.getElementById("direction").value=="update"){
//Change form1 to your real form name.
document.form1.action="update.php";
document.form1.submit();
}else{
alert("error happened. the direction unknown, unable to submit the form");
}
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.