0

I want to change page when I click the update/submit button. Here is my submit button code:

<td width="8%"><input type="submit" name="submit" value="Update" onclick="??????????"></td>

I place a question mark where I want the link/href would be place. Or you can suggest other methods to do that when I click update button it directs me to another php file. Thanks!

2 Answers 2

2

No onclick needed. onclick is for executing JS. This is done by setting action attribute for <form>.

<form method="POST" action="anotherPHPFile.php">
     <input type="submit" name="submit" value="Update">
</form>

After clicking on button, you will be redirected to anotherPHPFile.php.

Sign up to request clarification or add additional context in comments.

2 Comments

It is correct but not in my coding. Because I have an update db query below that line of code so when I put your suggestion it stops the code reading until there and switches to another php file. How can I update first the database when I click submit button then switches to another php file. Thanks!
Then change action to same PHP file. After submit, make query and redirect with header("Location: anotherPHPFile.php");
0

Do like this!

function redirect(e){
//If you want to check something here can prevent defualt button action
   // e.preventDefault()

//now do your action.

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");


// you can also use this line to do similar behavior as clicking on a link
// window.location.href = "http://stackoverflow.com";


}
<input type="submit" name="submit" value="Update" onclick="redirect()">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.