Hope someone can help me out with this problem I am having. I just dont get why my code isnt working properly. 🙁
I have a simple form with 2 input fields, a preview button and a submit button. The preview button uses this code to send the data to a preview page.
<script language="JavaScript">
<!--
function formpreview(form) {
form.target='_blank';
form.action='preview.php';
form.submit();
}
//-->
</script>
This is my form.
<form action="create_blog.php" method="post">
<p><font size="4">Topic</font><br><input type="text" name="topic" size="50" style="height:22px;font-size:1em;" accept-charset="ISO-8859-1"></p>
<font size="4">Content</font><br><textarea style="resize: none;" name="content" rows="30" cols="100"></textarea><br>
<input type="submit" value="Preview" onclick='formpreview(this.form)'>
<input type="submit" value="Save">
</form>
When I click the Save button first, it works. But if I click the preview first, and then the save button, the save button will work like the preview button instead of saving.
Any help is appreciated.
This is because your
formpreview()function is changing the default action value. You need a function that restores the action value to “create_blog.php”.