...

View Full Version : HELP - javascript function for alt. form action posts 2x



glenn.php
04-24-2008, 04:12 AM
I have a script that offers a second action on a form with one of two buttons calling the script and it keeps opening TWO new windows (and writing to my db twice! yeck!):



function OnButton1() {
document.form.action = "prev_post.php"
// document.form.target = "_blank"; // Open in a new window
document.form.submit(); // Submit the page
}

function OnButton2() {
document.form.action = "formProcess.php"
// document.form.target = "_blank"; // Open in a new window
document.form.submit(); // Submit the page
}

with the form tag thus:
<form method="post" name="form" id="form" />

and the buttons:

<input type="image" src="images/preview.gif" border="0" name=button1 onClick="OnButton1();">
<input type="image" src="images/preview.gif" border="0" name=button2 onClick="OnButton2();">

can someone kindly tell me what the heck is going on, or perhaps show me a better way to accomplish this...?

Many thanks
GN

Arty Effem
04-24-2008, 05:50 AM
function OnButton1() {
document.form.action = "prev_post.php"
// document.form.target = "_blank"; // Open in a new window
document.form.submit(); // Submit the page
}



<input type="image" src="images/preview.gif" border="0" name=button1 onClick="OnButton1();">
<input type="image" src="images/preview.gif" border="0" name=button2 onClick="OnButton2();">
Image type inputs are used to submit a form and do not require the submit method to be called. Try removing the calls.

glenn.php
04-24-2008, 05:54 AM
so then ' document.form.action = "prev_post.php" ' is actually doing the work, and ' document.form.submit(); ' repeating it...?

glenn.php
04-24-2008, 05:58 AM
yes, that worked, thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum